Work on items from wood

This commit is contained in:
marcin212 committed 2016-11-01 02:39:35 +01:00
1 parent 8c9cd7c202
commit a903d57103
6 files changed
+428 -117

No files matched your search

@@ -58,7 +58,7 @@ public class ExtraTrees extends AbstractMod {
public static Block blockStairs;
//public static Block blockLog;
public static BlockCarpentry blockCarpentry;
public static Block blockPlanks;
//public static Block blockPlanks;
public static Block blockMachine;
public static Block blockFence;
public static BlockCarpentry blockPanel;
@@ -1,96 +1,159 @@
package binnie.extratrees.block;
import binnie.Binnie;
import binnie.core.block.IBlockMetadata;
import binnie.core.block.TileEntityMetadata;
import binnie.extratrees.ExtraTrees;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.Tabs;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPlanks;
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.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class BlockETPlanks extends BlockPlanks implements IBlockMetadata {
public BlockETPlanks() {
this.setRegistryName("planks");
import static net.minecraft.block.BlockFence.*;
public class BlockETPlanks extends Block implements IItemModelRegister {
protected static final int VARIANTS_PER_BLOCK = 16;
protected static final int VARIANTS_META_MASK = VARIANTS_PER_BLOCK - 1;
private final boolean fireproof;
public static final int GROUP_COUNT = (int) Math.ceil(EnumExtraTreeLog.values().length / (float) VARIANTS_PER_BLOCK);
protected int offset = -1;
protected static PropertyEnum<EnumExtraTreeLog>[] plankTypes;
static {
plankTypes = new PropertyEnum[GROUP_COUNT];
for (int i = 0; i < GROUP_COUNT; i++) {
int finalI = i;
List allowed = Arrays.stream(EnumExtraTreeLog.values()).filter(l -> l.getMetadata() >= finalI * VARIANTS_PER_BLOCK && l.getMetadata() < finalI * VARIANTS_PER_BLOCK + VARIANTS_PER_BLOCK).collect(Collectors.toList());
plankTypes[i] = PropertyEnum.create("wood_type", EnumExtraTreeLog.class, allowed);
}
}
public BlockETPlanks(int offset, boolean fireproof) {
super(Material.WOOD);
this.fireproof = fireproof;
this.offset = offset;
this.setRegistryName("plank." + (fireproof ? "fireproof." : "") + offset);
this.setCreativeTab(Tabs.tabArboriculture);
this.setResistance(5.0f);
this.setHardness(2.0f);
this.setHarvestLevel("axe", 0);
this.setSoundType(SoundType.WOOD);
}
@Override
public int getPlacedMeta(ItemStack p0, World p1, BlockPos pos, EnumFacing p5) {
return 0;
public static class PlankItemBlock<V extends BlockETPlanks> extends ItemBlock {
EnumExtraTreeLog[] values;
public PlankItemBlock(V block) {
super(block);
setHasSubtypes(true);
setMaxDamage(0);
setRegistryName(block.getRegistryName());
values = block.getVariant().getAllowedValues().toArray(new EnumExtraTreeLog[]{});
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return "tile.plank." + values[stack.getMetadata()].getName();
}
}
// @Override
// public ArrayList<ItemStack> getDrops(final World world, final int x, final int y, final int z, final int blockMeta, final int fortune) {
// return BlockMetadata.getBlockDropped(this, world, x, y, z, blockMeta);
// }
//
// @Override
// public boolean removedByPlayer(final World world, final EntityPlayer player, final int x, final int y, final int z) {
// return BlockMetadata.breakBlock(this, player, world, x, y, z);
// }
@Override
public TileEntity createNewTileEntity(final World var1, final int i) {
return new TileEntityMetadata();
}
// @Override
// public boolean hasTileEntity(final int meta) {
// return true;
// }
//
// @Override
// public boolean onBlockEventReceived(final World par1World, final int par2, final int par3, final int par4, final int par5, final int par6) {
// super.onBlockEventReceived(par1World, par2, par3, par4, par5, par6);
// final TileEntity tileentity = par1World.getTileEntity(par2, par3, par4);
// return tileentity != null && tileentity.receiveClientEvent(par5, par6);
// }
//
// @Override
// public int getPlacedMeta(final ItemStack stack, final World world, final int x, final int y, final int z, final ForgeDirection clickedBlock) {
// return TileEntityMetadata.getItemDamage(stack);
// }
@Override
public int getDroppedMeta(final int blockMeta, final int tileMeta) {
return tileMeta;
public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
int meta = getMetaFromState(blockState);
EnumExtraTreeLog woodType = getWoodType(meta);
return woodType.getHardness();
}
@Override
public String getBlockName(final ItemStack par1ItemStack) {
final int meta = TileEntityMetadata.getItemDamage(par1ItemStack);
return Binnie.Language.localise(ExtraTrees.instance, "block.plank.name", PlankType.ExtraTreePlanks.values()[meta].getName());
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
if (fireproof) {
return 0;
}
return 20;
}
@Override
public void getBlockTooltip(final ItemStack par1ItemStack, final List par3List) {
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
if (fireproof) {
return 0;
}
return 5;
}
@Override
public void dropAsStack(World world, BlockPos pos, ItemStack p4) {
//this.dropBlockAsItem(world, pos, drop);
public int getMetaFromState(IBlockState state) {
return damageDropped(state);
}
// @Override
// public void dropAsStack(final World world, final int x, final int y, final int z, final ItemStack drop) {
// this.dropBlockAsItem(world, x, y, z, drop);
// }
@Override
public IBlockState getStateFromMeta(int meta) {
EnumExtraTreeLog woodType = getWoodType(meta);
return getDefaultState().withProperty(getVariant(), woodType);
}
// @Override
// public void getSubBlocks(final Item itemIn, final CreativeTabs par2CreativeTabs, final List<ItemStack> itemList) {
// for (int i = 0; i < PlankType.ExtraTreePlanks.values().length; ++i) {
// itemList.add(TileEntityMetadata.getItemStack(this, i));
// }
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, getVariant());
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
list.addAll(getVariant().getAllowedValues().stream().map(woodType -> new ItemStack(this, 1, woodType.getMetadata() % VARIANTS_PER_BLOCK)).collect(Collectors.toList()));
}
@Nonnull
public PropertyEnum<EnumExtraTreeLog> getVariant(){
return plankTypes[offset];
}
@Override
public final int damageDropped(IBlockState state) {
return state.getValue(getVariant()).getMetadata() % VARIANTS_PER_BLOCK;
}
@Override
public final IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
EnumExtraTreeLog woodType = getWoodType(meta);
return getDefaultState().withProperty(getVariant(), woodType);
}
public EnumExtraTreeLog getWoodType(int meta) {
return EnumExtraTreeLog.values()[offset * VARIANTS_PER_BLOCK + (meta & VARIANTS_META_MASK)];
}
@Override
public void registerModel(Item item, IModelManager manager) {
}
// public String getBlockName(final ItemStack par1ItemStack) {
// final int meta = TileEntityMetadata.getItemDamage(par1ItemStack);
// return Binnie.Language.localise(ExtraTrees.instance, "block.plank.name", PlankType.ExtraTreePlanks.values()[meta].getName());
// }
// @Override
@@ -115,36 +178,5 @@ public class BlockETPlanks extends BlockPlanks implements IBlockMetadata {
// plank.loadIcon(register);
// }
// }
//
// @Override
// public void breakBlock(final World par1World, final int par2, final int par3, final int par4, final Block par5, final int par6) {
// super.breakBlock(par1World, par2, par3, par4, par5, par6);
// par1World.removeTileEntity(par2, par3, par4);
// }
// @Override
// public boolean isWood(final IBlockAccess world, final int x, final int y, final int z) {
// return true;
// }
//
// @Override
// public int getFlammability(final IBlockAccess world, final int x, final int y, final int z, final ForgeDirection face) {
// return 20;
// }
//
// @Override
// public boolean isFlammable(final IBlockAccess world, final int x, final int y, final int z, final ForgeDirection face) {
// return true;
// }
//
// @Override
// public int getFireSpreadSpeed(final IBlockAccess world, final int x, final int y, final int z, final ForgeDirection face) {
// return 5;
// }
// @Override
// public ItemStack getPickBlock(final MovingObjectPosition target, final World world, final int x, final int y, final int z) {
// return BlockMetadata.getPickBlock(world, x, y, z);
// }
}
@@ -32,7 +32,10 @@ import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.ShapedOreRecipe;
import javax.annotation.Nonnull;
import static binnie.extratrees.block.BlockETLog.woodTypes;
import static binnie.extratrees.block.BlockETPlanks.plankTypes;
public class ModuleBlocks implements IInitializable {
// public static int hedgeRenderID;
@@ -40,37 +43,71 @@ public class ModuleBlocks implements IInitializable {
@Override
public void preInit() {
PlankType.setup();
ExtraTrees.blockPlanks = new BlockETPlanks();
//ExtraTrees.blockPlanks = new BlockETPlanks();
ExtraTrees.blockFence = new BlockFence("fence");
for (int i = 0; i < BlockETPlanks.GROUP_COUNT ; i++) {
int finalI = i;
BlockETPlanks blockETPlank = new BlockETPlanks(finalI, false) {
@Override
public PropertyEnum<EnumExtraTreeLog> getVariant() {return plankTypes[finalI];}
};
GameRegistry.register(blockETPlank);
Item plank = GameRegistry.register(new BlockETPlanks.PlankItemBlock<>(blockETPlank));
WoodAccess.getInstance().registerWithVariants(blockETPlank, WoodBlockKind.PLANKS, plankTypes[finalI], false);
ExtraTrees.proxy.setCustomStateMapper("plank", blockETPlank);
//fireproof
BlockETPlanks blockETPlankFireproof = new BlockETPlanks(finalI, true) {
@Override
public PropertyEnum<EnumExtraTreeLog> getVariant() {
return plankTypes[finalI];
}
};
GameRegistry.register(blockETPlankFireproof);
ExtraTrees.proxy.setCustomStateMapper("plank", blockETPlankFireproof);
Item plankFireproof = GameRegistry.register(new BlockETPlanks.PlankItemBlock<>(blockETPlankFireproof));
WoodAccess.getInstance().registerWithVariants(blockETPlankFireproof, WoodBlockKind.PLANKS, plankTypes[finalI], true);
for (EnumExtraTreeLog l : plankTypes[finalI].getAllowedValues()) {
BinnieCore.proxy.registermodel(plank, l.getMetadata() % BlockETPlanks.VARIANTS_PER_BLOCK, new ModelResourceLocation("extratrees:plank", "wood_type=" + l.getName()));
BinnieCore.proxy.registermodel(plankFireproof, l.getMetadata() % BlockETPlanks.VARIANTS_PER_BLOCK, new ModelResourceLocation("extratrees:plank", "wood_type=" + l.getName()));
}
}
for (int i = 0; i < BlockETLog.GROUP_COUNT; i++) {
int finalI = i;
BlockETLog block = new BlockETLog(finalI, false) {
BlockETLog blockETLog = new BlockETLog(finalI, false) {
@Override
public PropertyEnum<EnumExtraTreeLog> getVariant() {
return woodTypes[finalI];
}
};
GameRegistry.register(block);
Item wood = GameRegistry.register(new BlockETLog.LogItemBlock<>(block));
WoodAccess.registerWithVariants(block, WoodBlockKind.LOG, woodTypes[finalI]);
ExtraTrees.proxy.setCustomStateMapper("log", block);
GameRegistry.register(blockETLog);
Item wood = GameRegistry.register(new BlockETLog.LogItemBlock<>(blockETLog));
WoodAccess.getInstance().registerWithVariants(blockETLog, WoodBlockKind.LOG, woodTypes[finalI], false);
ExtraTrees.proxy.setCustomStateMapper("log", blockETLog);
//fireproof
BlockETLog block2 = new BlockETLog(i, true) {
BlockETLog blockETLogFireproof = new BlockETLog(i, true) {
@Override
public PropertyEnum<EnumExtraTreeLog> getVariant() {
return woodTypes[finalI];
}
};
GameRegistry.register(block2);
ExtraTrees.proxy.setCustomStateMapper("log", block2);
Item woodFireproof = GameRegistry.register(new BlockETLog.LogItemBlock<>(block2));
GameRegistry.register(blockETLogFireproof);
ExtraTrees.proxy.setCustomStateMapper("log", blockETLogFireproof);
Item woodFireproof = GameRegistry.register(new BlockETLog.LogItemBlock<>(blockETLogFireproof));
for (EnumExtraTreeLog l : woodTypes[finalI].getAllowedValues()) {
BinnieCore.proxy.registermodel(wood, l.getMetadata() % BlockETLog.VARIANTS_PER_BLOCK, new ModelResourceLocation("extratrees:log", "axis=y,wood_type=" + l.getName()));
BinnieCore.proxy.registermodel(woodFireproof, l.getMetadata() % BlockETLog.VARIANTS_PER_BLOCK, new ModelResourceLocation("extratrees:log", "axis=y,wood_type=" + l.getName()));
}
WoodAccess.getInstance().registerWithVariants(blockETLogFireproof, WoodBlockKind.LOG, woodTypes[finalI], true);
}
@@ -79,9 +116,9 @@ public class ModuleBlocks implements IInitializable {
ExtraTrees.blockMultiFence = new BlockMultiFence();
ExtraTrees.blockSlab = new BlockETSlab(false);
ExtraTrees.blockDoubleSlab = new BlockETSlab(true);
ExtraTrees.blockStairs = new BlockETStairs(ExtraTrees.blockPlanks);
GameRegistry.register(ExtraTrees.blockPlanks);
GameRegistry.register(new ItemMetadata(ExtraTrees.blockPlanks).setRegistryName(ExtraTrees.blockPlanks.getRegistryName()));
// ExtraTrees.blockStairs = new BlockETStairs(ExtraTrees.blockPlanks);
// GameRegistry.register(ExtraTrees.blockPlanks);
// GameRegistry.register(new ItemMetadata(ExtraTrees.blockPlanks).setRegistryName(ExtraTrees.blockPlanks.getRegistryName()));
GameRegistry.register(ExtraTrees.blockFence);
GameRegistry.register(new ItemMetadata(ExtraTrees.blockFence).setRegistryName(ExtraTrees.blockFence.getRegistryName()));
GameRegistry.register(ExtraTrees.blockMultiFence);
@@ -96,8 +133,8 @@ public class ModuleBlocks implements IInitializable {
GameRegistry.register(new ItemETSlab(ExtraTrees.blockDoubleSlab).setRegistryName(ExtraTrees.blockDoubleSlab.getRegistryName()));
GameRegistry.register(ExtraTrees.blockDoor);
GameRegistry.register(new ItemETDoor(ExtraTrees.blockDoor).setRegistryName(ExtraTrees.blockDoor.getRegistryName()));
GameRegistry.register(ExtraTrees.blockStairs);
GameRegistry.register(new ItemETStairs(ExtraTrees.blockStairs).setRegistryName(ExtraTrees.blockStairs.getRegistryName()));
// GameRegistry.register(ExtraTrees.blockStairs);
// GameRegistry.register(new ItemETStairs(ExtraTrees.blockStairs).setRegistryName(ExtraTrees.blockStairs.getRegistryName()));
//BinnieCore.proxy.registerCustomItemRenderer(Item.getItemFromBlock(ExtraTrees.blockStairs), new StairItemRenderer());
//BinnieCore.proxy.registerCustomItemRenderer(Item.getItemFromBlock(ExtraTrees.blockGate), new GateItemRenderer());
for (final EnumExtraTreeLog plank : EnumExtraTreeLog.values()) {
@@ -134,11 +171,11 @@ public class ModuleBlocks implements IInitializable {
for (final PlankType.ExtraTreePlanks plank : PlankType.ExtraTreePlanks.values()) {
final ItemStack planks = plank.getStack();
final ItemStack slabs = TileEntityMetadata.getItemStack(ExtraTrees.blockSlab, plank.ordinal());
final ItemStack stairs = TileEntityMetadata.getItemStack(ExtraTrees.blockStairs, plank.ordinal());
stairs.stackSize = 4;
GameRegistry.addRecipe(stairs.copy(), "# ", "## ", "###", '#', planks.copy());
slabs.stackSize = 6;
CraftingManager.getInstance().getRecipeList().add(0, new ShapedOreRecipe(slabs.copy(), "###", '#', planks.copy()));
//final ItemStack stairs = TileEntityMetadata.getItemStack(ExtraTrees.blockStairs, plank.ordinal());
//stairs.stackSize = 4;
//GameRegistry.addRecipe(stairs.copy(), "# ", "## ", "###", '#', planks.copy());
//slabs.stackSize = 6;
//CraftingManager.getInstance().getRecipeList().add(0, new ShapedOreRecipe(slabs.copy(), "###", '#', planks.copy()));
}
GameRegistry.addRecipe(new MultiFenceRecipeSize());
GameRegistry.addRecipe(new MultiFenceRecipeEmbedded());
@@ -11,6 +11,7 @@ import forestry.api.arboriculture.WoodBlockKind;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
public class PlankType {
public static final int MAX_PLANKS = 256;
@@ -30,7 +31,7 @@ public class PlankType {
}
}
public enum ExtraTreePlanks implements IPlankType, IFenceProvider {
public enum ExtraTreePlanks implements IPlankType, IFenceProvider, IStringSerializable {
Fir(12815444),
Cedar(14181940),
Hemlock(13088108),
@@ -91,7 +92,7 @@ public class PlankType {
@Override
public ItemStack getStack() {
return TileEntityMetadata.getItemStack(ExtraTrees.blockPlanks, this.ordinal());
return null; //TileEntityMetadata.getItemStack(ExtraTrees.blockPlanks, this.ordinal());
}
// public IIcon loadIcon(final IIconRegister register) {
@@ -12,19 +12,26 @@ import org.apache.commons.lang3.NotImplementedException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WoodAccess implements IWoodAccess {
private static HashMap<IWoodType, IBlockState> woodMap = new HashMap<>();
private WoodHolder wood = new WoodHolder();
private WoodHolder woodFireproof= new WoodHolder();
private static final WoodAccess instance = new WoodAccess();
public static WoodAccess getInstance() {
return instance;
}
public static <T extends Block, V extends Enum<V> & IWoodType> void registerWithVariants(T woodTyped, WoodBlockKind woodBlockKind, PropertyEnum<V> property) {
public <T extends Block, V extends Enum<V> & IWoodType> void registerWithVariants(T woodTyped, WoodBlockKind woodBlockKind, PropertyEnum<V> property, boolean fireproof) {
for (V value : property.getAllowedValues()) {
IBlockState blockState = woodTyped.getDefaultState().withProperty(property, value);
woodMap.put(value, blockState);
if(fireproof) {
wood.addWood(value, woodBlockKind, blockState);
}else {
woodFireproof.addWood(value, woodBlockKind, blockState);
}
}
}
@@ -35,7 +42,7 @@ public class WoodAccess implements IWoodAccess {
@Override
public IBlockState getBlock(IWoodType woodType, WoodBlockKind kind, boolean fireproof) {
IBlockState state = woodMap.get(woodType);
IBlockState state = fireproof?woodFireproof.getWood(woodType, kind) : wood.getWood(woodType, kind);
return state==null? TreeManager.woodAccess.getBlock(woodType, kind, fireproof) : state;
}
@@ -43,4 +50,22 @@ public class WoodAccess implements IWoodAccess {
public List<IWoodType> getRegisteredWoodTypes() {
throw new NotImplementedException("");
}
private class WoodHolder{
private Map<WoodBlockKind, Map<IWoodType, IBlockState>> woodMap = new HashMap<>();
public void addWood(IWoodType woodType, WoodBlockKind kind, IBlockState state){
Map<IWoodType, IBlockState> woodTypes = woodMap.get(kind);
if (woodTypes == null){
woodTypes = new HashMap<>();
woodMap.put(kind, woodTypes);
}
woodTypes.put(woodType, state);
}
public IBlockState getWood(IWoodType woodType, WoodBlockKind kind){
Map<IWoodType, IBlockState> woodTypes = woodMap.get(kind);
return woodTypes!=null ? woodTypes.get(woodType) : null;
}
}
}