Flattened casings

This commit is contained in:
drcrazy 2018-09-16 03:34:26 +03:00
parent 1d4116a215
commit f6c143dce3
21 changed files with 212 additions and 186 deletions

View file

@ -24,14 +24,10 @@
package techreborn.blocks;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -40,70 +36,70 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.api.ToolManager;
import reborncore.client.models.ModelCompound;
import reborncore.client.models.RebornModelRegistry;
import reborncore.common.RebornCoreConfig;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.blocks.PropertyString;
import reborncore.common.items.WrenchHelper;
import reborncore.common.multiblock.BlockMultiblockBase;
import reborncore.common.util.ArrayUtils;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
import techreborn.tiles.TileMachineCasing;
import techreborn.utils.TechRebornCreativeTab;
import java.security.InvalidParameterException;
import java.util.List;
import java.util.Random;
public class BlockMachineCasing extends BlockMultiblockBase {
public static final String[] types = new String[] { "standard", "reinforced", "advanced" };
public static final PropertyString TYPE = new PropertyString("type", types);
private static final List<String> typesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(types));
// public static final String[] types = new String[] { "standard", "reinforced", "advanced" };
// public static final PropertyString TYPE = new PropertyString("type", types);
// private static final List<String> typesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(types));
public BlockMachineCasing() {
super(Material.IRON);
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(2F);
this.setDefaultState(this.getDefaultState().withProperty(TYPE, "standard"));
for (int i = 0; i < types.length; i++) {
RebornModelRegistry.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i, "machines/structure").setInvVariant("type=" + types[i]));
}
RebornModelRegistry.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/structure"));
// this.setDefaultState(this.getDefaultState().withProperty(TYPE, "standard"));
// for (int i = 0; i < types.length; i++) {
// RebornModelRegistry.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i, "machines/structure").setInvVariant("type=" + types[i]));
// }
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
public static ItemStack getStackByName(String name, int count) {
name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModBlocks.MACHINE_CASINGS, count, i);
}
}
throw new InvalidParameterException("The machine casing " + name + " could not be found.");
}
public static ItemStack getStackByName(String name) {
return getStackByName(name, 1);
}
// public static ItemStack getStackByName(String name, int count) {
// name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
// for (int i = 0; i < types.length; i++) {
// if (types[i].equalsIgnoreCase(name)) {
// return new ItemStack(ModBlocks.MACHINE_CASINGS, count, i);
// }
// }
// throw new InvalidParameterException("The machine casing " + name + " could not be found.");
// }
//
// public static ItemStack getStackByName(String name) {
// return getStackByName(name, 1);
// }
/**
* Provides heat info per casing for Industrial Blast Furnace
* @param state Machine casing type
* @param state IBlockstate Blockstate with Machine casing
* @return Integer Heat value for casing
*/
public int getHeatFromState(IBlockState state) {
switch (getMetaFromState(state)) {
case 0:
return 1020 / 25;
case 1:
return 1700 / 25;
case 2:
return 2380 / 25;
Block casing = state.getBlock();
if (casing == null ) {
return 0;
}
if (casing == ModBlocks.MACHINE_CASINGS_STANDARD) {
return 1020 / 25;
}
else if (casing == ModBlocks.MACHINE_CASINGS_REINFORCED) {
return 1700 / 25;
}
else if (casing == ModBlocks.MACHINE_CASINGS_ADVANCED) {
return 2380 / 25;
}
return 0;
}
@ -111,10 +107,11 @@ public class BlockMachineCasing extends BlockMultiblockBase {
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
if (RebornCoreConfig.wrenchRequired){
if (state.getValue(TYPE) == "reinforced") {
Block casing = state.getBlock();
if (casing == ModBlocks.MACHINE_CASINGS_REINFORCED) {
drops.add(new ItemStack(ModBlocks.MACHINE_BLOCK_ADVANCED));
}
else if (state.getValue(TYPE) == "advanced") {
else if (casing == ModBlocks.MACHINE_CASINGS_ADVANCED) {
drops.add(new ItemStack(ModBlocks.MACHINE_BLOCK_ELITE));
}
else {
@ -146,41 +143,34 @@ public class BlockMachineCasing extends BlockMultiblockBase {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta > types.length) {
meta = 0;
}
return getBlockState().getBaseState().withProperty(TYPE, typesList.get(meta));
}
// @Override
// public IBlockState getStateFromMeta(int meta) {
// if (meta > types.length) {
// meta = 0;
// }
// return getBlockState().getBaseState().withProperty(TYPE, typesList.get(meta));
// }
//
// @Override
// public int getMetaFromState(IBlockState state) {
// return typesList.indexOf(state.getValue(TYPE));
// }
//
// @Override
// protected BlockStateContainer createBlockState() {
// return new BlockStateContainer(this, TYPE);
// }
//
// @Override
// public Item getItemDropped(IBlockState state, Random rand, int fortune) {
// return Item.getItemFromBlock(this);
// }
@Override
public int getMetaFromState(IBlockState state) {
return typesList.indexOf(state.getValue(TYPE));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, TYPE);
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(this);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
for (int meta = 0; meta < types.length; meta++) {
list.add(new ItemStack(this, 1, meta));
}
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
//
// @Override
// public int damageDropped(IBlockState state) {
// return getMetaFromState(state);
// }
@Override
public TileEntity createNewTileEntity(final World world, final int meta) {