Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.13.2 and refactor #17

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://www.jitpack.io' }
maven { url 'https://files.minecraftforge.net/maven' }
maven { url 'https://www.dimdev.org/maven/' }
}
dependencies {
classpath 'org.dimdev:ForgeGradle:2.3-SNAPSHOT'
classpath 'com.github.Chocohead:ForgeGradle:moderniser-SNAPSHOT'
}
}

Expand All @@ -20,16 +22,18 @@ targetCompatibility = 1.8

repositories {
mavenCentral()
maven { url 'https://www.jitpack.io' }
maven { url 'http://repo.strezz.org/artifactory/list/Strezz-Central' }
maven { url 'https://www.dimdev.org/maven/' }
}

dependencies {
implementation 'org.dimdev:rift:1.0.4-65:dev'
implementation 'com.github.Chocohead:Rift:jitpack-SNAPSHOT:dev'
}

minecraft {
version = '1.13'
mappings = 'snapshot_20180826'
version = '1.13.2'
mappings = 'snapshot_20181130'
runDir = 'run'
tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker'
}
171 changes: 82 additions & 89 deletions src/main/java/org/dimdev/halflogs/HalfLogs.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
package org.dimdev.halflogs;

import org.dimdev.rift.listener.BlockAdder;
import org.dimdev.rift.listener.ItemAdder;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.*;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.dimdev.rift.listener.BlockAdder;
import org.dimdev.rift.listener.ItemAdder;

import java.util.function.Supplier;

public class HalfLogs implements BlockAdder, ItemAdder {
public static final EnumProperty<EnumFacing.Axis> AXIS = EnumProperty.<EnumFacing.Axis>create("axis", EnumFacing.Axis.class);
public static final EnumProperty<EnumFacing.Axis> AXIS = BlockStateProperties.AXIS;

private static Supplier<BlockStairs> LOG_STAIRS = () -> {
Block block = Blocks.OAK_LOG;

return new BlockStairs(block.getDefaultState(), Block.Builder.create(Material.WOOD, MapColor.WOOD).hardnessAndResistance(2.0F, 3.0F).sound(SoundType.WOOD)) {
private static BlockStairs createLogStairs(Block log) {
return new BlockStairs(log.getDefaultState(), Block.Properties.from(log)) {
@Override
protected void fillStateContainer(StateContainer.Builder<Block,IBlockState> p_Builder) {
super.fillStateContainer(p_Builder);
p_Builder.add(AXIS);
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
super.fillStateContainer(builder);
builder.add(AXIS);
}

@Override
public IBlockState getStateForPlacement(BlockItemUseContext p_getBlockToPlaceOnUse_1_)
{
IBlockState iblockstate = super.getStateForPlacement(p_getBlockToPlaceOnUse_1_);
iblockstate = iblockstate.withProperty(AXIS, p_getBlockToPlaceOnUse_1_.getFace().getAxis());
return iblockstate;
public IBlockState getStateForPlacement(BlockItemUseContext context) {
IBlockState state = super.getStateForPlacement(context);
state = state.with(AXIS, context.getFace().getAxis());
return state;
}

@Override
public boolean onBlockActivated(IBlockState p_blockState, World p_world, BlockPos p_blockPos, EntityPlayer p_player, EnumHand p_hand, EnumFacing p_facing, float hitX, float hitY, float hitZ) {
ItemStack stack = p_hand == EnumHand.MAIN_HAND ? p_player.getHeldItemMainhand() : p_player.getHeldItemOffhand();
public boolean onBlockActivated(IBlockState state, World world, BlockPos pos, EntityPlayer player,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if (item instanceof ItemAxe) {
Block strippedBlock;
Expand All @@ -68,40 +67,39 @@ public boolean onBlockActivated(IBlockState p_blockState, World p_world, BlockPo
return false;
}

p_world.setBlockState(p_blockPos, strippedBlock.getDefaultState()
.withProperty(AXIS, p_blockState.getValue(AXIS))
.withProperty(BlockStairs.FACING, p_blockState.getValue(BlockStairs.FACING))
.withProperty(BlockStairs.HALF, p_blockState.getValue(BlockStairs.HALF))
.withProperty(BlockStairs.SHAPE, p_blockState.getValue(BlockStairs.SHAPE)));
p_world.playSound(p_player, p_blockPos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(1, p_player);
world.setBlockState(pos,
strippedBlock.getDefaultState().with(AXIS, state.get(AXIS))
.with(BlockStairs.FACING, state.get(BlockStairs.FACING))
.with(BlockStairs.HALF, state.get(BlockStairs.HALF))
.with(BlockStairs.SHAPE, state.get(BlockStairs.SHAPE)));
world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(1, player);
return true;
}
return false;
}
};
};

private static Supplier<BlockSlab> LOG_SLABS = () -> {
}

return new BlockSlab(Block.Builder.create(Material.WOOD, MapColor.WOOD).hardnessAndResistance(2.0F, 3.0F).sound(SoundType.WOOD)) {
private static BlockSlab createLogSlab(Block block) {
return new BlockSlab(Block.Properties.from(block)) {
@Override
protected void fillStateContainer(StateContainer.Builder<Block,IBlockState> p_Builder) {
super.fillStateContainer(p_Builder);
p_Builder.add(AXIS);
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
super.fillStateContainer(builder);
builder.add(AXIS);
}

@Override
public IBlockState getStateForPlacement(BlockItemUseContext p_getBlockToPlaceOnUse_1_)
{
IBlockState iblockstate = super.getStateForPlacement(p_getBlockToPlaceOnUse_1_);
iblockstate = iblockstate.withProperty(AXIS, p_getBlockToPlaceOnUse_1_.getFace().getAxis());
return iblockstate;
public IBlockState getStateForPlacement(BlockItemUseContext context) {
IBlockState state = super.getStateForPlacement(context);
state = state.with(AXIS, context.getFace().getAxis());
return state;
}

@Override
public boolean onBlockActivated(IBlockState p_blockState, World p_world, BlockPos p_blockPos, EntityPlayer p_player, EnumHand p_hand, EnumFacing p_facing, float hitX, float hitY, float hitZ) {
ItemStack stack = p_hand == EnumHand.MAIN_HAND ? p_player.getHeldItemMainhand() : p_player.getHeldItemOffhand();
public boolean onBlockActivated(IBlockState state, World world, BlockPos pos,
EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if (item instanceof ItemAxe) {
Block strippedBlock;
Expand All @@ -121,74 +119,71 @@ public boolean onBlockActivated(IBlockState p_blockState, World p_world, BlockPo
return false;
}

SlabType slabType = p_blockState.getValue(BlockSlab.TYPE);
p_world.setBlockState(p_blockPos, strippedBlock.getDefaultState()
.withProperty(AXIS, p_blockState.getValue(AXIS))
.withProperty(BlockSlab.TYPE, slabType));
p_world.playSound(p_player, p_blockPos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(slabType == SlabType.DOUBLE ? (p_world.rand.nextBoolean() ? 2 : 1) : 1, p_player); //just because
SlabType slabType = state.get(BlockSlab.TYPE);
world.setBlockState(pos, strippedBlock.getDefaultState().with(AXIS, state.get(AXIS))
.with(BlockSlab.TYPE, slabType));
world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F,
1.0F);
stack.damageItem(slabType == SlabType.DOUBLE ? (world.rand.nextBoolean() ? 2 : 1) : 1, player); // just
// because
return true;
}
return false;
}
};
};

//Slabs
public final static Block OAK_LOG_SLAB = LOG_SLABS.get();
public final static Block SPRUCE_LOG_SLAB = LOG_SLABS.get();
public final static Block BIRCH_LOG_SLAB = LOG_SLABS.get();
public final static Block JUNGLE_LOG_SLAB = LOG_SLABS.get();
public final static Block ACACIA_LOG_SLAB = LOG_SLABS.get();
public final static Block DARK_OAK_LOG_SLAB = LOG_SLABS.get();
//Stripped
public final static Block STRIPPED_OAK_LOG_SLAB = LOG_SLABS.get();
public final static Block STRIPPED_SPRUCE_LOG_SLAB = LOG_SLABS.get();
public final static Block STRIPPED_BIRCH_LOG_SLAB = LOG_SLABS.get();
public final static Block STRIPPED_JUNGLE_LOG_SLAB = LOG_SLABS.get();
public final static Block STRIPPED_ACACIA_LOG_SLAB = LOG_SLABS.get();
public final static Block STRIPPED_DARK_OAK_LOG_SLAB = LOG_SLABS.get();

//Stairs
public final static Block OAK_LOG_STAIRS = LOG_STAIRS.get();
public final static Block SPRUCE_LOG_STAIRS = LOG_STAIRS.get();
public final static Block BIRCH_LOG_STAIRS = LOG_STAIRS.get();
public final static Block JUNGLE_LOG_STAIRS = LOG_STAIRS.get();
public final static Block ACACIA_LOG_STAIRS = LOG_STAIRS.get();
public final static Block DARK_OAK_LOG_STAIRS = LOG_STAIRS.get();
//Stripped
public final static Block STRIPPED_OAK_LOG_STAIRS = LOG_STAIRS.get();
public final static Block STRIPPED_SPRUCE_LOG_STAIRS = LOG_STAIRS.get();
public final static Block STRIPPED_BIRCH_LOG_STAIRS = LOG_STAIRS.get();
public final static Block STRIPPED_JUNGLE_LOG_STAIRS = LOG_STAIRS.get();
public final static Block STRIPPED_ACACIA_LOG_STAIRS = LOG_STAIRS.get();
public final static Block STRIPPED_DARK_OAK_LOG_STAIRS = LOG_STAIRS.get();
}

public final static Block OAK_LOG_SLAB = createLogSlab(Blocks.OAK_LOG);
public final static Block SPRUCE_LOG_SLAB = createLogSlab(Blocks.SPRUCE_LOG);
public final static Block BIRCH_LOG_SLAB = createLogSlab(Blocks.BIRCH_LOG);
public final static Block JUNGLE_LOG_SLAB = createLogSlab(Blocks.JUNGLE_LOG);
public final static Block ACACIA_LOG_SLAB = createLogSlab(Blocks.ACACIA_LOG);
public final static Block DARK_OAK_LOG_SLAB = createLogSlab(Blocks.DARK_OAK_LOG);

public final static Block STRIPPED_OAK_LOG_SLAB = createLogSlab(Blocks.STRIPPED_OAK_LOG);
public final static Block STRIPPED_SPRUCE_LOG_SLAB = createLogSlab(Blocks.STRIPPED_SPRUCE_LOG);
public final static Block STRIPPED_BIRCH_LOG_SLAB = createLogSlab(Blocks.STRIPPED_BIRCH_LOG);
public final static Block STRIPPED_JUNGLE_LOG_SLAB = createLogSlab(Blocks.STRIPPED_JUNGLE_LOG);
public final static Block STRIPPED_ACACIA_LOG_SLAB = createLogSlab(Blocks.STRIPPED_ACACIA_LOG);
public final static Block STRIPPED_DARK_OAK_LOG_SLAB = createLogSlab(Blocks.STRIPPED_DARK_OAK_LOG);

public final static Block OAK_LOG_STAIRS = createLogStairs(Blocks.OAK_LOG);
public final static Block SPRUCE_LOG_STAIRS = createLogStairs(Blocks.SPRUCE_LOG);
public final static Block BIRCH_LOG_STAIRS = createLogStairs(Blocks.BIRCH_LOG);
public final static Block JUNGLE_LOG_STAIRS = createLogStairs(Blocks.JUNGLE_LOG);
public final static Block ACACIA_LOG_STAIRS = createLogStairs(Blocks.ACACIA_LOG);
public final static Block DARK_OAK_LOG_STAIRS = createLogStairs(Blocks.DARK_OAK_LOG);

public final static Block STRIPPED_OAK_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_OAK_LOG);
public final static Block STRIPPED_SPRUCE_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_SPRUCE_LOG);
public final static Block STRIPPED_BIRCH_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_BIRCH_LOG);
public final static Block STRIPPED_JUNGLE_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_JUNGLE_LOG);
public final static Block STRIPPED_ACACIA_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_ACACIA_LOG);
public final static Block STRIPPED_DARK_OAK_LOG_STAIRS = createLogStairs(Blocks.STRIPPED_DARK_OAK_LOG);

@Override
public void registerBlocks() {
//Slabs
Block.register(new ResourceLocation("halflogs:oak_log_slab"), OAK_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:spruce_log_slab"), SPRUCE_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:birch_log_slab"), BIRCH_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:jungle_log_slab"), JUNGLE_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:acacia_log_slab"), ACACIA_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:dark_oak_log_slab"), DARK_OAK_LOG_SLAB);
//Stripped

Block.register(new ResourceLocation("halflogs:stripped_oak_log_slab"), STRIPPED_OAK_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:stripped_spruce_log_slab"), STRIPPED_SPRUCE_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:stripped_birch_log_slab"), STRIPPED_BIRCH_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:stripped_jungle_log_slab"), STRIPPED_JUNGLE_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:stripped_acacia_log_slab"), STRIPPED_ACACIA_LOG_SLAB);
Block.register(new ResourceLocation("halflogs:stripped_dark_oak_log_slab"), STRIPPED_DARK_OAK_LOG_SLAB);

//Stairs
Block.register(new ResourceLocation("halflogs:oak_log_stairs"), OAK_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:spruce_log_stairs"), SPRUCE_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:birch_log_stairs"), BIRCH_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:jungle_log_stairs"), JUNGLE_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:acacia_log_stairs"), ACACIA_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:dark_oak_log_stairs"), DARK_OAK_LOG_STAIRS);
//Stripped

Block.register(new ResourceLocation("halflogs:stripped_oak_log_stairs"), STRIPPED_OAK_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:stripped_spruce_log_stairs"), STRIPPED_SPRUCE_LOG_STAIRS);
Block.register(new ResourceLocation("halflogs:stripped_birch_log_stairs"), STRIPPED_BIRCH_LOG_STAIRS);
Expand All @@ -199,29 +194,27 @@ public void registerBlocks() {

@Override
public void registerItems() {
//Slabs
Item.register(OAK_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(SPRUCE_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(BIRCH_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(JUNGLE_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(ACACIA_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(DARK_OAK_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
//Stripped

Item.register(STRIPPED_OAK_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_SPRUCE_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_BIRCH_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_JUNGLE_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_ACACIA_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_DARK_OAK_LOG_SLAB, ItemGroup.BUILDING_BLOCKS);

//Stairs
Item.register(OAK_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(SPRUCE_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(BIRCH_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(JUNGLE_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(ACACIA_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(DARK_OAK_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
//Stripped

Item.register(STRIPPED_OAK_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_SPRUCE_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Item.register(STRIPPED_BIRCH_LOG_STAIRS, ItemGroup.BUILDING_BLOCKS);
Expand Down
Loading