From de015cce204bf2ca3d14c0dcdfde0b26f9072f7c Mon Sep 17 00:00:00 2001 From: Dragon2488 Date: Mon, 14 Aug 2017 18:24:36 +0700 Subject: [PATCH] VariantBlock, VariantItemBlock, more casings --- .../gregtech/common/blocks/BlockCasings2.java | 20 +----- .../common/blocks/BlockMachineCasing.java | 63 ++++--------------- .../common/blocks/BlockMetalCasing.java | 42 +++++++++++++ .../common/blocks/BlockWarningSign.java | 53 ++-------------- .../gregtech/common/blocks/BlockWireCoil.java | 53 ++-------------- .../gregtech/common/blocks/VariantBlock.java | 61 ++++++++++++++++++ .../common/blocks/VariantItemBlock.java | 33 ++++++++++ 7 files changed, 158 insertions(+), 167 deletions(-) create mode 100644 src/main/java/gregtech/common/blocks/BlockMetalCasing.java create mode 100644 src/main/java/gregtech/common/blocks/VariantBlock.java create mode 100644 src/main/java/gregtech/common/blocks/VariantItemBlock.java diff --git a/src/main/java/gregtech/common/blocks/BlockCasings2.java b/src/main/java/gregtech/common/blocks/BlockCasings2.java index 06215f21..1b6dca15 100644 --- a/src/main/java/gregtech/common/blocks/BlockCasings2.java +++ b/src/main/java/gregtech/common/blocks/BlockCasings2.java @@ -1,8 +1,6 @@ package gregtech.common.blocks; -import gregtech.api.util.GT_LanguageManager; - -public class BlockCasings2 extends BlockCasingsAbstract { +public class BlockCasings2 { public BlockCasings2() { @@ -33,22 +31,6 @@ public class BlockCasings2 extends BlockCasingsAbstract { GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".12.name", "Tungstensteel Turbine Casing"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".10.name", "Stainless Steel Turbine Casing"); - //BlockMetalCasing - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".10.name", "Bronze Plated Bricks"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".0.name", "Solid Steel Machine Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".1.name", "Frost Proof Machine Casing"); //aluminium - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".11.name", "Heat Proof Machine Casing"); //invar - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".0.name", "Robust Tungstensteel Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".1.name", "Clean Stainless Steel Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".2.name", "Stable Titanium Casing"); - - //BlockMachineCasing - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".5.name", "Assembling Line Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".9.name", "Assembler Machine Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".6.name", "Fusion Casing"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".8.name", "Fusion Casing MK II"); - GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".13.name", "Engine Intake Casing"); - } } diff --git a/src/main/java/gregtech/common/blocks/BlockMachineCasing.java b/src/main/java/gregtech/common/blocks/BlockMachineCasing.java index 4da3a273..66048e7d 100644 --- a/src/main/java/gregtech/common/blocks/BlockMachineCasing.java +++ b/src/main/java/gregtech/common/blocks/BlockMachineCasing.java @@ -1,68 +1,24 @@ package gregtech.common.blocks; -import net.minecraft.block.Block; +import gregtech.api.GregTech_API; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import java.util.List; - -public class BlockMachineCasing extends Block { - - public static final PropertyEnum VARIANT = PropertyEnum.create("variant", MachineCasingType.class); +public class BlockMachineCasing extends VariantBlock { public BlockMachineCasing() { - super(Material.IRON); + super(Material.IRON, MachineCasingType.class); setHardness(5.0f); setResistance(3.0f); setSoundType(SoundType.METAL); setHarvestLevel("wrench", 2); - } - - @Override - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, VARIANT); - } - - @Override - @SuppressWarnings("deprecation") - public IBlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(VARIANT, MachineCasingType.values()[meta]); - } - - @Override - public int getMetaFromState(IBlockState state) { - return state.getValue(VARIANT).ordinal(); - } - - @Override - public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { - for(MachineCasingType casingType : MachineCasingType.values()) { - list.add(getItem(casingType)); - } - } - - public ItemStack getItem(MachineCasingType casingType) { - return new ItemStack(this, 1, casingType.ordinal()); - } - - @Override - public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, ItemStack stack) { - return getDefaultState().withProperty(VARIANT, MachineCasingType.values()[stack.getItemDamage()]); + setCreativeTab(GregTech_API.TAB_GREGTECH); } public enum MachineCasingType implements IStringSerializable { + //Voltage-tiered casings ULV("ultra_low_voltage"), LV("low_voltage"), MV("medium_voltage"), @@ -72,7 +28,14 @@ public class BlockMachineCasing extends Block { LuV("ludicrous_voltage"), ZPM("zero_point_module"), UV("ultra_voltage"), - MAX("maximum_voltage"); + MAX("maximum_voltage"), + + //Machine-specific casings + ENGINE_INTAKE("engine_intake"), + ASSEMBLER("assembler"), + ASSEMBLING_MACHINE("assembling_machine"), + FUSION("fusion"), + FUSION_MK2("fusion_mk2"); private final String name; diff --git a/src/main/java/gregtech/common/blocks/BlockMetalCasing.java b/src/main/java/gregtech/common/blocks/BlockMetalCasing.java new file mode 100644 index 00000000..d737f901 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockMetalCasing.java @@ -0,0 +1,42 @@ +package gregtech.common.blocks; + +import gregtech.api.GregTech_API; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.util.IStringSerializable; + +public class BlockMetalCasing extends VariantBlock { + + public BlockMetalCasing() { + super(Material.IRON, MetalCasingType.class); + setHardness(8.0f); + setResistance(6.0f); + setSoundType(SoundType.METAL); + setHarvestLevel("wrench", 2); + setCreativeTab(GregTech_API.TAB_GREGTECH); + } + + public enum MetalCasingType implements IStringSerializable { + + BRONZE_BRICKS("bronze_bricks"), + INVAR_HEATPROOF("invar_heatproof"), + ALUMINIUM_FROSTPROOF("aluminium_frostproof"), + STEEL_SOLID("steel_solid"), + STAINLESS_CLEAN("stainless_clean"), + TITANIUM_STABLE("titanium_stable"), + TUNGSTENSTEEL_ROBUST("tungstensteel_robust"); + + private final String name; + + MetalCasingType(String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + } + +} diff --git a/src/main/java/gregtech/common/blocks/BlockWarningSign.java b/src/main/java/gregtech/common/blocks/BlockWarningSign.java index ca938f0f..a8c9fde0 100644 --- a/src/main/java/gregtech/common/blocks/BlockWarningSign.java +++ b/src/main/java/gregtech/common/blocks/BlockWarningSign.java @@ -1,64 +1,19 @@ package gregtech.common.blocks; -import net.minecraft.block.Block; +import gregtech.api.GregTech_API; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import java.util.List; - -public class BlockWarningSign extends Block { - - public static final PropertyEnum VARIANT = PropertyEnum.create("variant", SignType.class); +public class BlockWarningSign extends VariantBlock { public BlockWarningSign() { - super(Material.IRON); + super(Material.IRON, SignType.class); setHardness(2.0f); setResistance(1.0f); setSoundType(SoundType.METAL); setHarvestLevel("pickaxe", 2); - } - - @Override - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, VARIANT); - } - - @Override - @SuppressWarnings("deprecation") - public IBlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(VARIANT, SignType.values()[meta]); - } - - @Override - public int getMetaFromState(IBlockState state) { - return state.getValue(VARIANT).ordinal(); - } - - @Override - public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { - for(SignType signType : SignType.values()) { - list.add(getItem(signType)); - } - } - - public ItemStack getItem(SignType signType) { - return new ItemStack(this, 1, signType.ordinal()); - } - - @Override - public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, ItemStack stack) { - return getDefaultState().withProperty(VARIANT, SignType.values()[stack.getItemDamage()]); + setCreativeTab(GregTech_API.TAB_GREGTECH); } public enum SignType implements IStringSerializable { diff --git a/src/main/java/gregtech/common/blocks/BlockWireCoil.java b/src/main/java/gregtech/common/blocks/BlockWireCoil.java index c47cfb25..c73ff52c 100644 --- a/src/main/java/gregtech/common/blocks/BlockWireCoil.java +++ b/src/main/java/gregtech/common/blocks/BlockWireCoil.java @@ -1,64 +1,19 @@ package gregtech.common.blocks; -import net.minecraft.block.Block; +import gregtech.api.GregTech_API; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import java.util.List; - -public class BlockWireCoil extends Block { - - public static final PropertyEnum VARIANT = PropertyEnum.create("variant", CoilType.class); +public class BlockWireCoil extends VariantBlock { public BlockWireCoil() { - super(Material.IRON); + super(Material.IRON, CoilType.class); setHardness(7.0f); setResistance(5.0f); setSoundType(SoundType.METAL); setHarvestLevel("wrench", 2); - } - - @Override - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, VARIANT); - } - - @Override - @SuppressWarnings("deprecation") - public IBlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(VARIANT, CoilType.values()[meta]); - } - - @Override - public int getMetaFromState(IBlockState state) { - return state.getValue(VARIANT).ordinal(); - } - - @Override - public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { - for(CoilType heatingCoilType : CoilType.values()) { - list.add(getItem(heatingCoilType)); - } - } - - public ItemStack getItem(CoilType coilType) { - return new ItemStack(this, 1, coilType.ordinal()); - } - - @Override - public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, ItemStack stack) { - return getDefaultState().withProperty(VARIANT, CoilType.values()[stack.getItemDamage()]); + setCreativeTab(GregTech_API.TAB_GREGTECH); } public enum CoilType implements IStringSerializable { diff --git a/src/main/java/gregtech/common/blocks/VariantBlock.java b/src/main/java/gregtech/common/blocks/VariantBlock.java new file mode 100644 index 00000000..928a9382 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/VariantBlock.java @@ -0,0 +1,61 @@ +package gregtech.common.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; + +import java.util.List; + +public class VariantBlock & IStringSerializable> extends Block { + + public final PropertyEnum VARIANT; + private final T[] VALUES; + + public VariantBlock(Material materialIn, Class enumClass) { + super(materialIn); + this.VARIANT = PropertyEnum.create("variant", enumClass); + this.VALUES = enumClass.getEnumConstants(); + } + + @Override + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + for(T variant : VALUES) { + list.add(getItemVariant(variant)); + } + } + + public T getVariant(IBlockState blockState) { + return blockState.getValue(VARIANT); + } + + public IBlockState withVariant(T variant) { + return getDefaultState().withProperty(VARIANT, variant); + } + + public ItemStack getItemVariant(T variant) { + return new ItemStack(this, 1, variant.ordinal()); + } + + @Override + protected BlockStateContainer createBlockState() { + return new BlockStateContainer(this, VARIANT); + } + + @Override + @SuppressWarnings("deprecation") + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(VARIANT, VALUES[meta]); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(VARIANT).ordinal(); + } + +} diff --git a/src/main/java/gregtech/common/blocks/VariantItemBlock.java b/src/main/java/gregtech/common/blocks/VariantItemBlock.java new file mode 100644 index 00000000..821b34a7 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/VariantItemBlock.java @@ -0,0 +1,33 @@ +package gregtech.common.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class VariantItemBlock extends ItemBlock { + + private PropertyEnum variant; + + public VariantItemBlock(Block block) { + super(block); + this.variant = (PropertyEnum) block.getBlockState().getProperty("variant"); + } + + @Override + public int getMetadata(int damage) { + return damage; + } + + @SuppressWarnings("deprecation") + protected IBlockState getBlockState(ItemStack stack) { + return block.getStateFromMeta(getMetadata(stack.getItemDamage())); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return super.getUnlocalizedName(stack) + '.' + getBlockState(stack).getValue(variant).getName(); + } + +}