VariantBlock, VariantItemBlock, more casings
This commit is contained in:
parent
8372d4d38d
commit
de015cce20
7 changed files with 158 additions and 167 deletions
|
@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<MachineCasingType> VARIANT = PropertyEnum.create("variant", MachineCasingType.class);
|
||||
public class BlockMachineCasing extends VariantBlock<BlockMachineCasing.MachineCasingType> {
|
||||
|
||||
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<ItemStack> 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;
|
||||
|
||||
|
|
42
src/main/java/gregtech/common/blocks/BlockMetalCasing.java
Normal file
42
src/main/java/gregtech/common/blocks/BlockMetalCasing.java
Normal file
|
@ -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<BlockMetalCasing.MetalCasingType> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<SignType> VARIANT = PropertyEnum.create("variant", SignType.class);
|
||||
public class BlockWarningSign extends VariantBlock<BlockWarningSign.SignType> {
|
||||
|
||||
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<ItemStack> 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 {
|
||||
|
|
|
@ -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<CoilType> VARIANT = PropertyEnum.create("variant", CoilType.class);
|
||||
public class BlockWireCoil extends VariantBlock<BlockWireCoil.CoilType> {
|
||||
|
||||
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<ItemStack> 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 {
|
||||
|
|
61
src/main/java/gregtech/common/blocks/VariantBlock.java
Normal file
61
src/main/java/gregtech/common/blocks/VariantBlock.java
Normal file
|
@ -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<T extends Enum<T> & IStringSerializable> extends Block {
|
||||
|
||||
public final PropertyEnum<T> VARIANT;
|
||||
private final T[] VALUES;
|
||||
|
||||
public VariantBlock(Material materialIn, Class<T> enumClass) {
|
||||
super(materialIn);
|
||||
this.VARIANT = PropertyEnum.create("variant", enumClass);
|
||||
this.VALUES = enumClass.getEnumConstants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> 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();
|
||||
}
|
||||
|
||||
}
|
33
src/main/java/gregtech/common/blocks/VariantItemBlock.java
Normal file
33
src/main/java/gregtech/common/blocks/VariantItemBlock.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue