Fix #1001 Slabs can't combine on placement in same block

This commit is contained in:
mezz committed 2015-12-30 04:34:23 -08:00
1 parent 45993f8213
commit ff7adac9e1
6 files changed
+214 -14

No files matched your search

@@ -12,6 +12,7 @@ package forestry.arboriculture.blocks;
import forestry.arboriculture.items.ItemBlockLeaves;
import forestry.arboriculture.items.ItemBlockWood;
import forestry.arboriculture.items.ItemBlockWoodSlab;
import forestry.core.blocks.BlockRegistry;
import forestry.core.items.ItemBlockForestry;
@@ -19,11 +20,13 @@ public class BlockRegistryArboriculture extends BlockRegistry {
public final BlockLog logs;
public final BlockPlanks planks;
public final BlockSlab slabs;
public final BlockSlab slabsDouble;
public final BlockArbFence fences;
public final BlockArbStairs stairs;
public final BlockLog logsFireproof;
public final BlockPlanks planksFireproof;
public final BlockSlab slabsFireproof;
public final BlockSlab slabsDoubleFireproof;
public final BlockArbFence fencesFireproof;
public final BlockArbStairs stairsFireproof;
@@ -40,9 +43,13 @@ public class BlockRegistryArboriculture extends BlockRegistry {
planks = registerBlock(new BlockPlanks(false), ItemBlockWood.class, "planks");
registerOreDictWildcard("plankWood", planks);
slabs = registerBlock(new BlockSlab(false), ItemBlockWood.class, "slabs");
BlockSlab blockSlab = new BlockSlab(false, false);
BlockSlab blockSlabDouble = new BlockSlab(true, false);
slabs = registerBlock(blockSlab, ItemBlockWoodSlab.class, "slabs", blockSlabDouble, blockSlab);
registerOreDictWildcard("slabWood", slabs);
slabsDouble = registerBlock(blockSlabDouble, ItemBlockWoodSlab.class, "slabsDouble", blockSlabDouble, blockSlab);
fences = registerBlock(new BlockArbFence(false), ItemBlockWood.class, "fences");
registerOreDictWildcard("fenceWood", fences);
@@ -55,9 +62,13 @@ public class BlockRegistryArboriculture extends BlockRegistry {
planksFireproof = registerBlock(new BlockPlanks(true), ItemBlockWood.class, "planksFireproof");
registerOreDictWildcard("plankWood", planksFireproof);
slabsFireproof = registerBlock(new BlockSlab(true), ItemBlockWood.class, "slabsFireproof");
BlockSlab blockSlabFireproof = new BlockSlab(false, true);
BlockSlab blockSlabDoubleFireproof = new BlockSlab(true, true);
slabsFireproof = registerBlock(blockSlabFireproof, ItemBlockWoodSlab.class, "slabsFireproof", blockSlabDoubleFireproof, blockSlabFireproof);
registerOreDictWildcard("slabWood", slabsFireproof);
slabsDoubleFireproof = registerBlock(blockSlabDoubleFireproof, ItemBlockWoodSlab.class, "slabsDoubleFireproof", blockSlabDoubleFireproof, blockSlabFireproof);
fencesFireproof = registerBlock(new BlockArbFence(true), ItemBlockWood.class, "fencesFireproof");
registerOreDictWildcard("fenceWood", fencesFireproof);
@@ -46,8 +46,8 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
private final ParticleHelper.Callback particleCallback;
private final boolean fireproof;
public BlockSlab(boolean fireproof) {
super(false, Material.wood);
public BlockSlab(boolean doubleSlab, boolean fireproof) {
super(doubleSlab, Material.wood);
this.fireproof = fireproof;
@@ -61,9 +61,8 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
this.particleCallback = new ParticleHelper.DefaultCallback(this);
}
@Override
public boolean isOpaqueCube() {
return false;
public boolean isDoubleSlab() {
return field_150004_a;
}
/* ICONS */
@@ -100,8 +99,10 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List list) {
for (EnumWoodType woodType : EnumWoodType.VALUES) {
list.add(TreeManager.woodItemAccess.getSlab(woodType, fireproof));
if (!isDoubleSlab()) {
for (EnumWoodType woodType : EnumWoodType.VALUES) {
list.add(TreeManager.woodItemAccess.getSlab(woodType, fireproof));
}
}
}
@@ -44,6 +44,10 @@ public class ItemBlockWood extends ItemBlockForestry {
EnumWoodType woodType = getWoodType(stack);
Block block = Block.getBlockFromItem(stack.getItem());
return placeWood(stack, woodType, block, player, world, x, y, z, metadata);
}
public static boolean placeWood(ItemStack stack, EnumWoodType woodType, Block block, @Nullable EntityPlayer player, World world, int x, int y, int z, int metadata) {
boolean placed = world.setBlock(x, y, z, block, metadata, Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
if (!placed) {
return false;
@@ -0,0 +1,173 @@
package forestry.arboriculture.items;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.arboriculture.EnumWoodType;
import forestry.arboriculture.blocks.BlockSlab;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.tiles.TileUtil;
public class ItemBlockWoodSlab extends ItemBlockWood {
private final BlockSlab slab;
private final BlockSlab doubleSlab;
private final boolean isDoubleSlab;
public ItemBlockWoodSlab(Block block, BlockSlab doubleSlab, BlockSlab slab) {
super(block);
this.doubleSlab = doubleSlab;
this.slab = slab;
this.isDoubleSlab = (block == doubleSlab);
}
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (isDoubleSlab) {
return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
} else if (itemStack.stackSize == 0) {
return false;
} else if (!player.canPlayerEdit(x, y, z, side, itemStack)) {
return false;
} else {
Block block = world.getBlock(x, y, z);
int i1 = world.getBlockMetadata(x, y, z);
boolean flag = (i1 & 8) != 0;
EnumWoodType blockWoodType = null;
EnumWoodType stackWoodType = getWoodType(itemStack);
TileWood tile = TileUtil.getTile(world, x, y, z, TileWood.class);
if (tile != null) {
blockWoodType = tile.getWoodType();
}
if ((side == 1 && !flag || side == 0 && flag) && block == this.slab && blockWoodType == stackWoodType) {
if (world.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(world, x, y, z))) {
if (placeWood(itemStack, stackWoodType, doubleSlab, player, world, x, y, z, 0)) {
world.playSoundEffect((double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), this.doubleSlab.stepSound.func_150496_b(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getPitch() * 0.8F);
--itemStack.stackSize;
}
}
return true;
} else {
if (this.func_150946_a(itemStack, player, world, x, y, z, side)) {
return true;
} else {
return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
}
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack itemStack) {
int i1 = x;
int j1 = y;
int k1 = z;
Block block = world.getBlock(x, y, z);
int l1 = world.getBlockMetadata(x, y, z);
boolean flag = (l1 & 8) != 0;
EnumWoodType blockWoodType = null;
EnumWoodType stackWoodType = getWoodType(itemStack);
TileWood tile = TileUtil.getTile(world, x, y, z, TileWood.class);
if (tile != null) {
blockWoodType = tile.getWoodType();
}
if ((side == 1 && !flag || side == 0 && flag) && block == this.slab && stackWoodType == blockWoodType) {
return true;
} else {
if (side == 0) {
--y;
}
if (side == 1) {
++y;
}
if (side == 2) {
--z;
}
if (side == 3) {
++z;
}
if (side == 4) {
--x;
}
if (side == 5) {
++x;
}
Block block1 = world.getBlock(x, y, z);
tile = TileUtil.getTile(world, x, y, z, TileWood.class);
if (tile == null) {
blockWoodType = null;
} else {
blockWoodType = tile.getWoodType();
}
if (block1 == this.slab && stackWoodType == blockWoodType) {
return true;
} else {
return super.func_150936_a(world, i1, j1, k1, side, player, itemStack);
}
}
}
private boolean func_150946_a(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side) {
if (side == 0) {
--y;
}
if (side == 1) {
++y;
}
if (side == 2) {
--z;
}
if (side == 3) {
++z;
}
if (side == 4) {
--x;
}
if (side == 5) {
++x;
}
Block block = world.getBlock(x, y, z);
EnumWoodType blockWoodType = null;
EnumWoodType stackWoodType = getWoodType(itemStack);
TileWood tile = TileUtil.getTile(world, x, y, z, TileWood.class);
if (tile != null) {
blockWoodType = tile.getWoodType();
}
if (block == this.slab && blockWoodType == stackWoodType) {
if (world.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(world, x, y, z))) {
if (placeWood(itemStack, stackWoodType, doubleSlab, player, world, x, y, z, 0)) {
world.playSoundEffect((double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), this.doubleSlab.stepSound.func_150496_b(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getPitch() * 0.8F);
--itemStack.stackSize;
}
}
return true;
} else {
return false;
}
}
}
@@ -23,12 +23,14 @@ import net.minecraft.world.World;
import forestry.api.arboriculture.EnumWoodType;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.blocks.BlockSlab;
import forestry.arboriculture.items.ItemBlockWood;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.network.packets.PacketTileStream;
import forestry.core.tiles.TileUtil;
import forestry.plugins.PluginArboriculture;
public class TileWood extends TileEntity implements IStreamable {
private EnumWoodType woodType;
@@ -93,7 +95,16 @@ public class TileWood extends TileEntity implements IStreamable {
}
EnumWoodType woodType = wood.getWoodType();
ItemStack itemStack = new ItemStack(block);
int amount = 1;
if (block instanceof BlockSlab) {
BlockSlab blockSlab = (BlockSlab) block;
if (blockSlab.isDoubleSlab()) {
amount = 2;
block = PluginArboriculture.blocks.slabs;
}
}
ItemStack itemStack = new ItemStack(block, amount);
ItemBlockWood.saveToItemStack(woodType, itemStack);
return itemStack;
}
@@ -22,12 +22,12 @@ import forestry.core.utils.StringUtil;
import forestry.plugins.PluginManager;
public abstract class BlockRegistry {
protected static <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass, String name) {
protected static <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass, String name, Object... itemCtorArgs) {
if (PluginManager.getStage() != PluginManager.Stage.SETUP) {
throw new RuntimeException("Tried to register Block outside of Setup");
}
block.setBlockName("for." + name);
GameRegistry.registerBlock(block, itemClass, StringUtil.cleanBlockName(block));
GameRegistry.registerBlock(block, itemClass, StringUtil.cleanBlockName(block), itemCtorArgs);
return block;
}