From 6daa78de20ef6913dfb3b1c01b7f97d3c2fe6cd4 Mon Sep 17 00:00:00 2001 From: pahimar Date: Thu, 26 Dec 2013 20:59:51 -0500 Subject: [PATCH] Just some refactoring before a sprint of work tomorrow --- .../ee3/block/BlockAlchemicalChest.java | 2 +- .../pahimar/ee3/block/BlockAludelBase.java | 2 +- .../pahimar/ee3/block/BlockCalcinator.java | 2 +- .../pahimar/ee3/block/BlockContainerEE.java | 77 ++++++++++++++++++ .../java/com/pahimar/ee3/block/BlockEE.java | 78 +------------------ .../com/pahimar/ee3/block/BlockGlassBell.java | 2 +- .../java/com/pahimar/ee3/emc/EmcRegistry.java | 2 +- 7 files changed, 86 insertions(+), 79 deletions(-) create mode 100644 src/main/java/com/pahimar/ee3/block/BlockContainerEE.java diff --git a/src/main/java/com/pahimar/ee3/block/BlockAlchemicalChest.java b/src/main/java/com/pahimar/ee3/block/BlockAlchemicalChest.java index 3cf7a1af..3cd6b3c1 100644 --- a/src/main/java/com/pahimar/ee3/block/BlockAlchemicalChest.java +++ b/src/main/java/com/pahimar/ee3/block/BlockAlchemicalChest.java @@ -24,7 +24,7 @@ import java.util.Random; * * @author pahimar */ -public class BlockAlchemicalChest extends BlockEE +public class BlockAlchemicalChest extends BlockContainerEE { /** diff --git a/src/main/java/com/pahimar/ee3/block/BlockAludelBase.java b/src/main/java/com/pahimar/ee3/block/BlockAludelBase.java index b01d90be..736aa151 100644 --- a/src/main/java/com/pahimar/ee3/block/BlockAludelBase.java +++ b/src/main/java/com/pahimar/ee3/block/BlockAludelBase.java @@ -27,7 +27,7 @@ import java.util.Random; * * @author pahimar */ -public class BlockAludelBase extends BlockEE +public class BlockAludelBase extends BlockContainerEE { /** diff --git a/src/main/java/com/pahimar/ee3/block/BlockCalcinator.java b/src/main/java/com/pahimar/ee3/block/BlockCalcinator.java index c84bdb61..be79f41f 100644 --- a/src/main/java/com/pahimar/ee3/block/BlockCalcinator.java +++ b/src/main/java/com/pahimar/ee3/block/BlockCalcinator.java @@ -23,7 +23,7 @@ import java.util.Random; * * @author pahimar */ -public class BlockCalcinator extends BlockEE +public class BlockCalcinator extends BlockContainerEE { /** * Is the random generator used by calcinator to drop the inventory contents in random directions. diff --git a/src/main/java/com/pahimar/ee3/block/BlockContainerEE.java b/src/main/java/com/pahimar/ee3/block/BlockContainerEE.java new file mode 100644 index 00000000..674b0f07 --- /dev/null +++ b/src/main/java/com/pahimar/ee3/block/BlockContainerEE.java @@ -0,0 +1,77 @@ +package com.pahimar.ee3.block; + +import com.pahimar.ee3.lib.Reference; +import com.pahimar.ee3.tileentity.TileEE; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; + +/** + * Equivalent-Exchange-3 + *

+ * BlockContainerEE + * + * @author pahimar + */ +public abstract class BlockContainerEE extends BlockContainer +{ + public BlockContainerEE(int id, Material material) + { + super(id, material); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister iconRegister) + { + blockIcon = iconRegister.registerIcon(String.format("%s:%s", Reference.MOD_ID.toLowerCase(), getUnwrappedUnlocalizedName(this.getUnlocalizedName()))); + } + + protected String getUnwrappedUnlocalizedName(String unlocalizedName) + { + return unlocalizedName.substring(unlocalizedName.indexOf(":") + 1); + } + + /** + * Sets the direction of the block when placed + */ + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) + { + int direction = 0; + int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; + + if (facing == 0) + { + direction = ForgeDirection.NORTH.ordinal(); + } + else if (facing == 1) + { + direction = ForgeDirection.EAST.ordinal(); + } + else if (facing == 2) + { + direction = ForgeDirection.SOUTH.ordinal(); + } + else if (facing == 3) + { + direction = ForgeDirection.WEST.ordinal(); + } + + world.setBlockMetadataWithNotify(x, y, z, direction, 3); + + if (itemStack.hasDisplayName()) + { + ((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName()); + } + + ((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction); + } +} diff --git a/src/main/java/com/pahimar/ee3/block/BlockEE.java b/src/main/java/com/pahimar/ee3/block/BlockEE.java index 613ec743..7538f43e 100644 --- a/src/main/java/com/pahimar/ee3/block/BlockEE.java +++ b/src/main/java/com/pahimar/ee3/block/BlockEE.java @@ -1,82 +1,12 @@ package com.pahimar.ee3.block; -import com.pahimar.ee3.lib.Reference; -import com.pahimar.ee3.tileentity.TileEE; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.BlockContainer; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; -/** - * Equivalent-Exchange-3 - *

- * BlockEE - * - * @author pahimar - */ -public abstract class BlockEE extends BlockContainer +public class BlockEE extends Block { - - public BlockEE(int id, Material material) + public BlockEE(int id) { - - super(id, material); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IconRegister iconRegister) - { - - blockIcon = iconRegister.registerIcon(String.format("%s:%s", Reference.MOD_ID.toLowerCase(), getUnwrappedUnlocalizedName(this.getUnlocalizedName()))); - } - - protected String getUnwrappedUnlocalizedName(String unlocalizedName) - { - - return unlocalizedName.substring(unlocalizedName.indexOf(":") + 1); - } - - /** - * Sets the direction of the block when placed - */ - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) - { - - int direction = 0; - int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; - - if (facing == 0) - { - direction = ForgeDirection.NORTH.ordinal(); - } - else if (facing == 1) - { - direction = ForgeDirection.EAST.ordinal(); - } - else if (facing == 2) - { - direction = ForgeDirection.SOUTH.ordinal(); - } - else if (facing == 3) - { - direction = ForgeDirection.WEST.ordinal(); - } - - world.setBlockMetadataWithNotify(x, y, z, direction, 3); - - if (itemStack.hasDisplayName()) - { - ((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName()); - } - - ((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction); + super(id, Material.rock); } } diff --git a/src/main/java/com/pahimar/ee3/block/BlockGlassBell.java b/src/main/java/com/pahimar/ee3/block/BlockGlassBell.java index 7071b40b..1d65a840 100644 --- a/src/main/java/com/pahimar/ee3/block/BlockGlassBell.java +++ b/src/main/java/com/pahimar/ee3/block/BlockGlassBell.java @@ -24,7 +24,7 @@ import net.minecraftforge.common.ForgeDirection; import java.util.Random; -public class BlockGlassBell extends BlockEE +public class BlockGlassBell extends BlockContainerEE { /** diff --git a/src/main/java/com/pahimar/ee3/emc/EmcRegistry.java b/src/main/java/com/pahimar/ee3/emc/EmcRegistry.java index a08b4eaf..f8162e98 100644 --- a/src/main/java/com/pahimar/ee3/emc/EmcRegistry.java +++ b/src/main/java/com/pahimar/ee3/emc/EmcRegistry.java @@ -97,7 +97,7 @@ public class EmcRegistry { passNumber++; computedStackValues = computeStackMappings(); - + // TODO Duplicate entry protection stackMappingsBuilder = ImmutableSortedMap.naturalOrder(); stackMappingsBuilder.putAll(stackMappings); stackMappingsBuilder.putAll(computedStackValues);