mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 19:59:49 +00:00
Improve wood blocks
This commit is contained in:
1 parent
3ed915f9d5
commit
a990ce3dc9
33 files changed
+465
-1604
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package binnie.extratrees.block;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import binnie.Constants;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
|
||||
@@ -46,6 +48,8 @@ public enum EnumExtraTreeLog implements IWoodType {
|
||||
PinkIvory("Pink Ivory", PlankType.ExtraTreePlanks.PinkIvory),
|
||||
EMPTY("EMPTY", PlankType.VanillaPlanks.OAK);//TODO change name/create wood for SHRUBS
|
||||
|
||||
public static final EnumExtraTreeLog[] VALUES = values();
|
||||
|
||||
String name;
|
||||
IPlankType plank;
|
||||
|
||||
@@ -118,5 +122,13 @@ public enum EnumExtraTreeLog implements IWoodType {
|
||||
public int getMetadata() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static EnumExtraTreeLog byMetadata(int meta) {
|
||||
if (meta < 0 || meta >= VALUES.length) {
|
||||
meta = 0;
|
||||
}
|
||||
return VALUES[meta];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package binnie.extratrees.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.core.IInitializable;
|
||||
import binnie.core.Mods;
|
||||
import binnie.core.block.ItemMetadata;
|
||||
@@ -7,18 +10,32 @@ import binnie.core.liquid.ILiquidType;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.decor.*;
|
||||
import binnie.extratrees.block.log.BlockETLog;
|
||||
import binnie.extratrees.block.log.ItemETLog;
|
||||
import binnie.extratrees.block.plank.BlockETPlank;
|
||||
import binnie.extratrees.block.plank.ItemETPlank;
|
||||
import binnie.extratrees.block.slab.BlockETSlab;
|
||||
import binnie.extratrees.block.stairs.BlockETStairs;
|
||||
import binnie.extratrees.genetics.WoodAccess;
|
||||
import binnie.extratrees.block.slab.ItemETSlab;
|
||||
import binnie.extratrees.block.stairs.ItemETStairs;
|
||||
import binnie.extratrees.item.ExtraTreeLiquid;
|
||||
import forestry.api.arboriculture.EnumVanillaWoodType;
|
||||
import forestry.api.arboriculture.IWoodAccess;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.arboriculture.WoodAccess;
|
||||
import forestry.arboriculture.blocks.BlockForestryStairs;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
@@ -31,10 +48,93 @@ public class ModuleBlocks implements IInitializable {
|
||||
public void preInit() {
|
||||
PlankType.setup();
|
||||
|
||||
BlockETLog.init();
|
||||
BlockETPlank.init();
|
||||
BlockETSlab.init();
|
||||
BlockETStairs.init();
|
||||
//TODO: clean up
|
||||
ExtraTrees.logs = BlockETLog.create(false);
|
||||
for (BlockETLog block : ExtraTrees.logs) {
|
||||
ExtraTrees.proxy.registerBlock(block, new ItemETLog(block));
|
||||
registerOreDictWildcard(OreDictUtil.LOG_WOOD, block);
|
||||
}
|
||||
|
||||
ExtraTrees.logsFireproof = BlockETLog.create(true);
|
||||
for (BlockETLog block : ExtraTrees.logsFireproof) {
|
||||
ExtraTrees.proxy.registerBlock(block, new ItemETLog(block));
|
||||
registerOreDictWildcard(OreDictUtil.LOG_WOOD, block);
|
||||
}
|
||||
|
||||
WoodAccess.registerLogs(ExtraTrees.logs);
|
||||
WoodAccess.registerLogs(ExtraTrees.logsFireproof);
|
||||
|
||||
ExtraTrees.planks = BlockETPlank.create(false);
|
||||
for (BlockETPlank block : ExtraTrees.planks) {
|
||||
ExtraTrees.proxy.registerBlock(block, new ItemETPlank(block));
|
||||
registerOreDictWildcard(OreDictUtil.PLANK_WOOD, block);
|
||||
}
|
||||
|
||||
ExtraTrees.planksFireproof = BlockETPlank.create(true);
|
||||
for (BlockETPlank block : ExtraTrees.planksFireproof) {
|
||||
ExtraTrees.proxy.registerBlock(block, new ItemETPlank(block));
|
||||
registerOreDictWildcard(OreDictUtil.PLANK_WOOD, block);
|
||||
}
|
||||
|
||||
WoodAccess.registerPlanks(ExtraTrees.planks);
|
||||
WoodAccess.registerPlanks(ExtraTrees.planksFireproof);
|
||||
|
||||
ExtraTrees.slabs = BlockETSlab.create(false, false);
|
||||
ExtraTrees.slabsDouble = BlockETSlab.create(false, true);
|
||||
for (int i = 0; i < ExtraTrees.slabs.size(); i++) {
|
||||
BlockETSlab slab = ExtraTrees.slabs.get(i);
|
||||
BlockETSlab slabDouble = ExtraTrees.slabsDouble.get(i);
|
||||
ExtraTrees.proxy.registerBlock(slab, new ItemETSlab(slab, slab, slabDouble));
|
||||
ExtraTrees.proxy.registerBlock(slabDouble, new ItemETSlab(slabDouble, slab, slabDouble));
|
||||
registerOreDictWildcard(OreDictUtil.SLAB_WOOD, slab);
|
||||
}
|
||||
|
||||
ExtraTrees.slabsFireproof = BlockETSlab.create(true, false);
|
||||
ExtraTrees.slabsDoubleFireproof = BlockETSlab.create(true, true);
|
||||
for (int i = 0; i < ExtraTrees.slabsFireproof.size(); i++) {
|
||||
BlockETSlab slab = ExtraTrees.slabsFireproof.get(i);
|
||||
BlockETSlab slabDouble = ExtraTrees.slabsDoubleFireproof.get(i);
|
||||
ExtraTrees.proxy.registerBlock(slab, new ItemETSlab(slab, slab, slabDouble));
|
||||
ExtraTrees.proxy.registerBlock(slabDouble, new ItemETSlab(slabDouble, slab, slabDouble));
|
||||
registerOreDictWildcard(OreDictUtil.SLAB_WOOD, slab);
|
||||
}
|
||||
WoodAccess.registerSlabs(ExtraTrees.slabs);
|
||||
WoodAccess.registerSlabs(ExtraTrees.slabsFireproof);
|
||||
|
||||
ExtraTrees.stairs = new ArrayList<>();
|
||||
for (BlockETPlank plank : ExtraTrees.planks) {
|
||||
for (IBlockState blockState : plank.getBlockState().getValidStates()) {
|
||||
int meta = plank.getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = plank.getWoodType(meta);
|
||||
|
||||
BlockForestryStairs stair = new BlockForestryStairs(false, blockState, woodType);
|
||||
String name = "stairs." + woodType;
|
||||
stair.setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, name));
|
||||
stair.setUnlocalizedName(name);
|
||||
ExtraTrees.proxy.registerBlock(stair, new ItemETStairs(stair));
|
||||
ExtraTrees.stairs.add(stair);
|
||||
registerOreDictWildcard(OreDictUtil.STAIR_WOOD, stair);
|
||||
}
|
||||
}
|
||||
|
||||
ExtraTrees.stairsFireproof = new ArrayList<>();
|
||||
for (BlockETPlank plank : ExtraTrees.planksFireproof) {
|
||||
for (IBlockState blockState : plank.getBlockState().getValidStates()) {
|
||||
int meta = plank.getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = plank.getWoodType(meta);
|
||||
|
||||
BlockForestryStairs stair = new BlockForestryStairs(true, blockState, woodType);
|
||||
String name = "stairs.fireproof." + woodType;
|
||||
stair.setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, "stairs.fireproof." + woodType));
|
||||
stair.setUnlocalizedName(name);
|
||||
ExtraTrees.proxy.registerBlock(stair, new ItemETStairs(stair));
|
||||
ExtraTrees.stairsFireproof.add(stair);
|
||||
registerOreDictWildcard(OreDictUtil.STAIR_WOOD, stair);
|
||||
}
|
||||
}
|
||||
|
||||
WoodAccess.registerStairs(ExtraTrees.stairs);
|
||||
WoodAccess.registerStairs(ExtraTrees.stairsFireproof);
|
||||
|
||||
ExtraTrees.blockFence = new BlockFence("fence");
|
||||
ExtraTrees.blockGate = new BlockGate();
|
||||
@@ -54,16 +154,14 @@ public class ModuleBlocks implements IInitializable {
|
||||
// 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()) {
|
||||
OreDictionary.registerOre("logWood", WoodAccess.getInstance().getStack(plank, WoodBlockKind.LOG, false));
|
||||
OreDictionary.registerOre("plankWood", WoodAccess.getInstance().getStack(plank, WoodBlockKind.PLANKS, false));
|
||||
for (BlockETLog log : ExtraTrees.logs) {
|
||||
ItemStack logInput = new ItemStack(log, 1, OreDictionary.WILDCARD_VALUE);
|
||||
ItemStack coalOutput = new ItemStack(Items.COAL, 1, 1);
|
||||
RecipeUtil.addSmelting(logInput, coalOutput, 0.15F);
|
||||
}
|
||||
// GameRegistry.addSmelting(ExtraTrees.blockLog, new ItemStack(Items.COAL, 1, 1), 0.15f);
|
||||
// FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:fence");
|
||||
// FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:gate");
|
||||
// FMLInterModComms.sendMessage("Forestry", "add-alveary-slab",
|
||||
// "ExtraTrees:slab");
|
||||
// FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:multifence");
|
||||
FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:fence");
|
||||
FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:gate");
|
||||
FMLInterModComms.sendMessage("forestry", "add-fence-block", "ExtraTrees:multifence");
|
||||
//ModuleBlocks.hedgeRenderID = BinnieCore.proxy.getUniqueRenderID();
|
||||
}
|
||||
|
||||
@@ -83,14 +181,21 @@ public class ModuleBlocks implements IInitializable {
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
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()));
|
||||
IWoodAccess woodAccess = TreeManager.woodAccess;
|
||||
for(EnumExtraTreeLog woodType : EnumExtraTreeLog.VALUES){
|
||||
for(boolean fireproof : new boolean[]{false, true}){
|
||||
ItemStack planks = woodAccess.getStack(woodType, WoodBlockKind.PLANKS, fireproof);
|
||||
ItemStack slabs = woodAccess.getStack(woodType, WoodBlockKind.SLAB, fireproof);
|
||||
ItemStack stairs = woodAccess.getStack(woodType, WoodBlockKind.STAIRS, fireproof);
|
||||
stairs.stackSize = 4;
|
||||
RecipeUtil.addPriorityRecipe(stairs.copy(),
|
||||
"# ",
|
||||
"## ",
|
||||
"###",
|
||||
'#', planks.copy());
|
||||
slabs.stackSize = 6;
|
||||
RecipeUtil.addPriorityRecipe(slabs.copy(), "###", '#', planks.copy());
|
||||
}
|
||||
}
|
||||
GameRegistry.addRecipe(new MultiFenceRecipeSize());
|
||||
GameRegistry.addRecipe(new MultiFenceRecipeEmbedded());
|
||||
@@ -128,4 +233,13 @@ public class ModuleBlocks implements IInitializable {
|
||||
public void addSqueezer(final IWoodType log, final ILiquidType liquid, final int amount) {
|
||||
this.addSqueezer(log, liquid, amount, 0.5f);
|
||||
}
|
||||
|
||||
private static void addRecipeAtPosition(int position, IRecipe recipe){
|
||||
CraftingManager manager = CraftingManager.getInstance();
|
||||
manager.getRecipeList().add(position, recipe);
|
||||
}
|
||||
|
||||
private static void registerOreDictWildcard(String oreDictName, Block block) {
|
||||
OreDictionary.registerOre(oreDictName, new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package binnie.extratrees.block;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forestry.arboriculture.blocks.WoodTypePredicate;
|
||||
import forestry.arboriculture.blocks.property.PropertyWoodType;
|
||||
|
||||
public class PropertyExtraTreeWoodType extends PropertyWoodType<EnumExtraTreeLog> {
|
||||
public static PropertyExtraTreeWoodType[] create(@Nonnull String name, int variantsPerBlock) {
|
||||
final int variantCount = (int) Math.ceil((float) EnumExtraTreeLog.VALUES.length / variantsPerBlock);
|
||||
PropertyExtraTreeWoodType[] variants = new PropertyExtraTreeWoodType[variantCount];
|
||||
for (int variantNumber = 0; variantNumber < variantCount; variantNumber++) {
|
||||
WoodTypePredicate filter = new WoodTypePredicate(variantNumber, variantsPerBlock);
|
||||
Collection<EnumExtraTreeLog> allowedValues = Collections2.filter(Lists.newArrayList(EnumExtraTreeLog.class.getEnumConstants()), filter);
|
||||
variants[variantNumber] = new PropertyExtraTreeWoodType(name, EnumExtraTreeLog.class, allowedValues);
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
protected PropertyExtraTreeWoodType(String name, Class<EnumExtraTreeLog> valueClass, Collection<EnumExtraTreeLog> allowedValues) {
|
||||
super(name, valueClass, allowedValues);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,10 @@ import binnie.extratrees.api.CarpentryManager;
|
||||
import binnie.extratrees.api.IDesignMaterial;
|
||||
import binnie.extratrees.block.decor.FenceDescription;
|
||||
import binnie.extratrees.block.decor.FenceType;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -14,7 +18,36 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class WoodManager {
|
||||
@Nonnull
|
||||
public static String getDisplayName(IWoodTyped wood, IWoodType woodType) {
|
||||
WoodBlockKind blockKind = wood.getBlockKind();
|
||||
|
||||
String displayName;
|
||||
|
||||
if (woodType instanceof EnumExtraTreeLog) {
|
||||
String customUnlocalizedName = "tile.et." + blockKind + "." + woodType + ".name";
|
||||
if (Translator.canTranslateToLocal(customUnlocalizedName)) {
|
||||
displayName = Translator.translateToLocal(customUnlocalizedName);
|
||||
} else {
|
||||
String woodGrammar = Translator.translateToLocal("for." + blockKind + ".grammar");
|
||||
String woodTypeName = Translator.translateToLocal("et.trees.woodType." + woodType);
|
||||
|
||||
displayName = woodGrammar.replaceAll("%TYPE", woodTypeName);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown wood type: " + woodType);
|
||||
}
|
||||
|
||||
if (wood.isFireproof()) {
|
||||
displayName = Translator.translateToLocalFormatted("tile.for.fireproof", displayName);
|
||||
}
|
||||
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public static IPlankType getPlankType(final int index) {
|
||||
final IDesignMaterial wood = CarpentryManager.carpentryInterface.getWoodMaterial(index);
|
||||
if (wood instanceof IPlankType) {
|
||||
|
||||
@@ -1,205 +1,50 @@
|
||||
package binnie.extratrees.block.log;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import binnie.extratrees.block.IWoodKind;
|
||||
import binnie.extratrees.block.PropertyEnumWoodType;
|
||||
import binnie.extratrees.genetics.WoodAccess;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import net.minecraft.block.BlockLog;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import binnie.extratrees.block.PropertyExtraTreeWoodType;
|
||||
import forestry.arboriculture.blocks.log.BlockForestryLog;
|
||||
import forestry.arboriculture.blocks.property.PropertyWoodType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class BlockETLog extends BlockLog implements IWoodKind, IStateMapperRegister, IItemModelRegister {
|
||||
protected static final int VARIANTS_PER_BLOCK = 4;
|
||||
protected static final int VARIANTS_META_MASK = VARIANTS_PER_BLOCK - 1;
|
||||
public static final String BLOCK_NAME = "log";
|
||||
protected int offset = -1;
|
||||
protected boolean fireproof;
|
||||
protected static PropertyEnumWoodType[] types = PropertyEnumWoodType.create(VARIANTS_PER_BLOCK);
|
||||
|
||||
public BlockETLog(int offset, boolean fireproof) {
|
||||
this.setCreativeTab(Tabs.tabArboriculture);
|
||||
this.setRegistryName(BLOCK_NAME + "." + (fireproof ? "fireproof." : "") + offset);
|
||||
this.setResistance(5.0f);
|
||||
this.setHardness(2.0f);
|
||||
this.setSoundType(SoundType.WOOD);
|
||||
this.setUnlocalizedName(BLOCK_NAME + "." + (fireproof ? "fireproof." : "") + offset);
|
||||
this.offset = offset;
|
||||
this.fireproof = fireproof;
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(types[offset], types[offset].getFirstValue()).withProperty(LOG_AXIS, EnumAxis.Y));
|
||||
public abstract class BlockETLog extends BlockForestryLog<EnumExtraTreeLog> {
|
||||
public static List<BlockETLog> create(boolean fireproof) {
|
||||
List<BlockETLog> blocks = new ArrayList<>();
|
||||
PropertyExtraTreeWoodType[] variants = PropertyExtraTreeWoodType.create("variant", VARIANTS_PER_BLOCK);
|
||||
for (int i = 0; i < variants.length; i++) {
|
||||
PropertyExtraTreeWoodType variant = variants[i];
|
||||
BlockETLog block = new BlockETLog(fireproof, i) {
|
||||
@Nonnull
|
||||
@Override
|
||||
public PropertyWoodType<EnumExtraTreeLog> getVariant() {
|
||||
return variant;
|
||||
}
|
||||
};
|
||||
blocks.add(block);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private BlockETLog(boolean fireproof, int blockNumber) {
|
||||
super(fireproof, blockNumber);
|
||||
String name = "logs.";
|
||||
if(fireproof){
|
||||
name+="fireproof.";
|
||||
}
|
||||
name+=blockNumber;
|
||||
setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, name));
|
||||
setUnlocalizedName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract PropertyEnum<EnumExtraTreeLog> getVariant();
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumExtraTreeLog getWoodType(int meta) {
|
||||
return EnumExtraTreeLog.values()[offset * VARIANTS_PER_BLOCK + (meta & VARIANTS_META_MASK)];
|
||||
}
|
||||
|
||||
private static EnumAxis getAxis(int meta) {
|
||||
switch (meta & 12) {
|
||||
case 0:
|
||||
return EnumAxis.Y;
|
||||
case 4:
|
||||
return EnumAxis.X;
|
||||
case 8:
|
||||
return EnumAxis.Z;
|
||||
default:
|
||||
return EnumAxis.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final IBlockState getStateFromMeta(int meta) {
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
EnumAxis axis = getAxis(meta);
|
||||
return getDefaultState().withProperty(getVariant(), woodType).withProperty(LOG_AXIS, axis);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public final int getMetaFromState(IBlockState state) {
|
||||
int i = 0;
|
||||
try {
|
||||
i = damageDropped(state);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
switch (state.getValue(LOG_AXIS)) {
|
||||
case X:
|
||||
i |= 4;
|
||||
break;
|
||||
case Z:
|
||||
i |= 8;
|
||||
break;
|
||||
case NONE:
|
||||
i |= 12;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, getVariant(), LOG_AXIS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final int damageDropped(IBlockState state) {
|
||||
return state.getValue(getVariant()).getMetadata() % VARIANTS_PER_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final ItemStack createStackedBlock(IBlockState state) {
|
||||
int meta = damageDropped(state);
|
||||
Item item = Item.getItemFromBlock(this);
|
||||
return new ItemStack(item, 1, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
|
||||
EnumAxis axis = EnumAxis.fromFacingAxis(facing.getAxis());
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return getDefaultState().withProperty(getVariant(), woodType).withProperty(LOG_AXIS, axis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final 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()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
int meta = getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return woodType.getHardness();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
} else if (face == EnumFacing.DOWN) {
|
||||
return 20;
|
||||
} else if (face != EnumFacing.UP) {
|
||||
return 10;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WoodBlockKind getWoodKind() {
|
||||
return WoodBlockKind.LOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, stack -> new ModelResourceLocation(Constants.EXTRA_TREES_MOD_ID + ":" + BLOCK_NAME, "axis=y,wood_type=" + getWoodType(stack.getMetadata()).getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
ExtraTrees.proxy.setCustomStateMapper(BLOCK_NAME, this);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Arrays.stream(types).forEach(type -> {
|
||||
BlockETLog log = new BlockETLog(type.getGroup(), false) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETLog log_fireproof = new BlockETLog(type.getGroup(), true) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
ExtraTrees.proxy.registerItem(new ItemETLog<>(log));
|
||||
ExtraTrees.proxy.registerItem(new ItemETLog<>(log_fireproof));
|
||||
ExtraTrees.proxy.registerBlock(log);
|
||||
ExtraTrees.proxy.registerBlock(log_fireproof);
|
||||
|
||||
WoodAccess.getInstance().registerWithVariants(log, log.getWoodKind(), type, true);
|
||||
WoodAccess.getInstance().registerWithVariants(log_fireproof, log.getWoodKind(), type, false);
|
||||
});
|
||||
|
||||
int variantCount = getVariant().getAllowedValues().size();
|
||||
int variantMeta = (meta % variantCount) + getBlockNumber() * VARIANTS_PER_BLOCK;
|
||||
return EnumExtraTreeLog.byMetadata(variantMeta);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +1,26 @@
|
||||
package binnie.extratrees.block.log;
|
||||
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.items.ItemBlockWood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemETLog <V extends BlockETLog> extends ItemBlock {
|
||||
EnumExtraTreeLog[] values;
|
||||
public class ItemETLog <V extends BlockETLog> extends ItemBlockWood<V> {
|
||||
|
||||
public ItemETLog(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." + BlockETLog.BLOCK_NAME + "." + values[stack.getMetadata()].getName();
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
IWoodTyped wood = getBlock();
|
||||
int meta = itemstack.getMetadata();
|
||||
IWoodType woodType = wood.getWoodType(meta);
|
||||
return WoodManager.getDisplayName(wood, woodType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,157 +1,50 @@
|
||||
package binnie.extratrees.block.plank;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import binnie.extratrees.block.IWoodKind;
|
||||
import binnie.extratrees.block.PropertyEnumWoodType;
|
||||
import binnie.extratrees.genetics.WoodAccess;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import net.minecraft.block.Block;
|
||||
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.client.renderer.block.model.ModelResourceLocation;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import binnie.extratrees.block.PropertyExtraTreeWoodType;
|
||||
import forestry.arboriculture.blocks.planks.BlockForestryPlanks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class BlockETPlank extends Block implements IWoodKind, IItemModelRegister, IStateMapperRegister {
|
||||
protected static final int VARIANTS_PER_BLOCK = 16;
|
||||
protected static final int VARIANTS_META_MASK = VARIANTS_PER_BLOCK - 1;
|
||||
public abstract class BlockETPlank extends BlockForestryPlanks<EnumExtraTreeLog> {
|
||||
public static final String BLOCK_NAME = "plank";
|
||||
private final boolean fireproof;
|
||||
protected int offset = -1;
|
||||
protected static PropertyEnumWoodType[] types = PropertyEnumWoodType.create(VARIANTS_PER_BLOCK);
|
||||
|
||||
public BlockETPlank(int offset, boolean fireproof) {
|
||||
super(Material.WOOD);
|
||||
this.fireproof = fireproof;
|
||||
this.offset = offset;
|
||||
this.setRegistryName(BLOCK_NAME + "." + (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 float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
int meta = getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return woodType.getHardness();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
|
||||
public static List<BlockETPlank> create(boolean fireproof) {
|
||||
List<BlockETPlank> blocks = new ArrayList<>();
|
||||
PropertyExtraTreeWoodType[] variants = PropertyExtraTreeWoodType.create("variant", VARIANTS_PER_BLOCK);
|
||||
for (int i = 0; i < variants.length; i++) {
|
||||
PropertyExtraTreeWoodType variant = variants[i];
|
||||
BlockETPlank block = new BlockETPlank(fireproof, i) {
|
||||
@Nonnull
|
||||
@Override
|
||||
public PropertyExtraTreeWoodType getVariant() {
|
||||
return variant;
|
||||
}
|
||||
};
|
||||
blocks.add(block);
|
||||
}
|
||||
return 20;
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
private BlockETPlank(boolean fireproof, int blockNumber) {
|
||||
super(fireproof, blockNumber);
|
||||
String name = "planks.";
|
||||
if(fireproof){
|
||||
name+="fireproof.";
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return damageDropped(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return getDefaultState().withProperty(getVariant(), woodType);
|
||||
}
|
||||
|
||||
@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()));
|
||||
}
|
||||
|
||||
@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);
|
||||
name+=blockNumber;
|
||||
setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, name));
|
||||
setUnlocalizedName(name);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumExtraTreeLog getWoodType(int meta) {
|
||||
return EnumExtraTreeLog.values()[offset * VARIANTS_PER_BLOCK + (meta & VARIANTS_META_MASK)];
|
||||
int variantCount = getVariant().getAllowedValues().size();
|
||||
int variantMeta = (meta % variantCount) + getBlockNumber() * VARIANTS_PER_BLOCK;
|
||||
return EnumExtraTreeLog.byMetadata(variantMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WoodBlockKind getWoodKind() {
|
||||
return WoodBlockKind.PLANKS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
ExtraTrees.proxy.setCustomStateMapper(BLOCK_NAME, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, stack -> new ModelResourceLocation(Constants.EXTRA_TREES_MOD_ID + ":" + BLOCK_NAME, "wood_type=" + getWoodType(stack.getMetadata()).getName()));
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Arrays.stream(types).forEach(type -> {
|
||||
BlockETPlank plank = new BlockETPlank(type.getGroup(), false) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETPlank plank_fireproof = new BlockETPlank(type.getGroup(), true) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
ExtraTrees.proxy.registerItem(new ItemETPlank<>(plank));
|
||||
ExtraTrees.proxy.registerItem(new ItemETPlank<>(plank_fireproof));
|
||||
ExtraTrees.proxy.registerBlock(plank);
|
||||
ExtraTrees.proxy.registerBlock(plank_fireproof);
|
||||
|
||||
WoodAccess.getInstance().registerWithVariants(plank, plank.getWoodKind(), type, true);
|
||||
WoodAccess.getInstance().registerWithVariants(plank_fireproof, plank.getWoodKind(), type, false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,26 @@
|
||||
package binnie.extratrees.block.plank;
|
||||
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.arboriculture.IWoodTyped;
|
||||
import forestry.arboriculture.items.ItemBlockWood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by Marcin on 03.11.2016.
|
||||
*/
|
||||
public class ItemETPlank<V extends BlockETPlank> extends ItemBlock {
|
||||
EnumExtraTreeLog[] values;
|
||||
public class ItemETPlank<V extends BlockETPlank> extends ItemBlockWood<V> {
|
||||
|
||||
public ItemETPlank(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." + BlockETPlank.BLOCK_NAME + "." + values[stack.getMetadata()].getName();
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
IWoodTyped wood = getBlock();
|
||||
int meta = itemstack.getMetadata();
|
||||
IWoodType woodType = wood.getWoodType(meta);
|
||||
return WoodManager.getDisplayName(wood, woodType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,229 +1,58 @@
|
||||
package binnie.extratrees.block.slab;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import binnie.extratrees.block.IWoodKind;
|
||||
import binnie.extratrees.block.PropertyEnumWoodType;
|
||||
import binnie.extratrees.block.plank.BlockETPlank;
|
||||
import binnie.extratrees.genetics.WoodAccess;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import binnie.extratrees.block.PropertyExtraTreeWoodType;
|
||||
import forestry.arboriculture.blocks.slab.BlockForestrySlab;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BlockETSlab extends BlockSlab implements IWoodKind, IItemModelRegister, IStateMapperRegister{
|
||||
protected static final int VARIANTS_PER_BLOCK = 8;
|
||||
protected static final int VARIANTS_META_MASK = VARIANTS_PER_BLOCK - 1;
|
||||
public static final String BLOCK_NAME = "slab";
|
||||
private final boolean fireproof;
|
||||
private final int offset;
|
||||
protected static final PropertyEnumWoodType[] types = PropertyEnumWoodType.create(VARIANTS_PER_BLOCK);
|
||||
public abstract class BlockETSlab extends BlockForestrySlab<EnumExtraTreeLog> {
|
||||
public static List<BlockETSlab> create(boolean fireproof, final boolean doubleSlab) {
|
||||
List<BlockETSlab> blocks = new ArrayList<>();
|
||||
PropertyExtraTreeWoodType[] variants = PropertyExtraTreeWoodType.create("variant", VARIANTS_PER_BLOCK);
|
||||
for (int i = 0; i < variants.length; i++) {
|
||||
PropertyExtraTreeWoodType variant = variants[i];
|
||||
BlockETSlab block = new BlockETSlab(fireproof, i) {
|
||||
@Nonnull
|
||||
@Override
|
||||
public PropertyExtraTreeWoodType getVariant() {
|
||||
return variant;
|
||||
}
|
||||
|
||||
public BlockETSlab(int offset, boolean fireproof) {
|
||||
super(Material.WOOD);
|
||||
this.fireproof = fireproof;
|
||||
this.offset = offset;
|
||||
setCreativeTab(Tabs.tabArboriculture);
|
||||
setHardness(2.0f);
|
||||
setResistance(5.0f);
|
||||
setSoundType(SoundType.WOOD);
|
||||
setLightOpacity(0);
|
||||
setRegistryName(BLOCK_NAME + "." + (fireproof ? "fireproof." : "") + (isDouble()?"double.":"") + offset);
|
||||
@Override
|
||||
public boolean isDouble() {
|
||||
return doubleSlab;
|
||||
}
|
||||
};
|
||||
blocks.add(block);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private BlockETSlab(boolean fireproof, int blockNumber) {
|
||||
super(fireproof, blockNumber);
|
||||
String name = "slabs.";
|
||||
if(fireproof){
|
||||
name+="fireproof.";
|
||||
}
|
||||
if(isDouble()){
|
||||
name+="double.";
|
||||
}
|
||||
name+=blockNumber;
|
||||
setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, name));
|
||||
setUnlocalizedName(name);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumExtraTreeLog getWoodType(int meta) {
|
||||
return EnumExtraTreeLog.values()[offset * VARIANTS_PER_BLOCK + (meta & VARIANTS_META_MASK)];
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return this.isDouble() ? new BlockStateContainer(this, getVariant()) : new BlockStateContainer(this, HALF, getVariant());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
IBlockState iblockstate = this.getDefaultState().withProperty(getVariant(), woodType);
|
||||
|
||||
if (!this.isDouble()) {
|
||||
iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
|
||||
}
|
||||
|
||||
return iblockstate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
int meta = damageDropped(state);
|
||||
|
||||
if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP) {
|
||||
meta |= 8;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
EnumExtraTreeLog woodType = state.getValue(getVariant());
|
||||
return woodType.getMetadata() - offset * VARIANTS_PER_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
||||
EnumExtraTreeLog woodType = state.getValue(getVariant());
|
||||
ItemStack slab = WoodAccess.getInstance().getStack(woodType, WoodBlockKind.SLAB, fireproof);
|
||||
return slab.getItem();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // this is the way the vanilla slabs work
|
||||
@Override
|
||||
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
|
||||
EnumExtraTreeLog woodType = state.getValue(getVariant());
|
||||
ItemStack slab = WoodAccess.getInstance().getStack(woodType, WoodBlockKind.SLAB, fireproof);
|
||||
return new ItemStack(slab.getItem(), 1, getMetaFromState(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> list) {
|
||||
if (!isDouble()) {
|
||||
list.addAll(getVariant().getAllowedValues().stream().map(woodType -> new ItemStack(this, 1, woodType.getMetadata() % VARIANTS_PER_BLOCK)).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
int meta = getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return woodType.getHardness();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
return fireproof ? 0 : 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
return fireproof ? 0 : 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(int meta) {
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return woodType.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty<?> getVariantProperty() {
|
||||
return getVariant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable<?> getTypeForItem(ItemStack stack) {
|
||||
return getWoodType(stack.getMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WoodBlockKind getWoodKind() {
|
||||
return WoodBlockKind.SLAB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if(!isDouble())
|
||||
manager.registerItemModel(item, stack -> new ModelResourceLocation(Constants.EXTRA_TREES_MOD_ID + ":" + BLOCK_NAME, "half=bottom,wood_type=" + getWoodType(stack.getMetadata()).getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
if(isDouble())
|
||||
ExtraTrees.proxy.setCustomStateMapper(BlockETPlank.BLOCK_NAME, this);
|
||||
else
|
||||
ExtraTrees.proxy.setCustomStateMapper(BLOCK_NAME, this);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Arrays.stream(types).forEach(type -> {
|
||||
BlockETSlab slab = new BlockETSlab(type.getGroup(), false) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETSlab slab_double = new BlockETSlab(type.getGroup(), false) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETSlab slab_fireproof = new BlockETSlab(type.getGroup(), true) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETSlab slab_double_fireproof = new BlockETSlab(type.getGroup(), true) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ExtraTrees.proxy.registerItem(new ItemETSlab<>(slab, slab_double));
|
||||
ExtraTrees.proxy.registerItem(new ItemETSlab<>(slab_fireproof, slab_double_fireproof));
|
||||
ExtraTrees.proxy.registerBlock(slab);
|
||||
ExtraTrees.proxy.registerBlock(slab_fireproof);
|
||||
ExtraTrees.proxy.registerBlock(slab_double);
|
||||
ExtraTrees.proxy.registerBlock(slab_double_fireproof);
|
||||
|
||||
WoodAccess.getInstance().registerWithVariants(slab, slab.getWoodKind(), type, true);
|
||||
WoodAccess.getInstance().registerWithVariants(slab_fireproof, slab.getWoodKind(), type, false);
|
||||
});
|
||||
|
||||
meta &= ~8; // unset the top/bottom slab bit
|
||||
int variantCount = getVariant().getAllowedValues().size();
|
||||
int variantMeta = (meta % variantCount) + getBlockNumber() * VARIANTS_PER_BLOCK;
|
||||
return EnumExtraTreeLog.byMetadata(variantMeta);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,22 @@
|
||||
package binnie.extratrees.block.slab;
|
||||
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import net.minecraft.item.ItemSlab;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemETSlab<V extends BlockETSlab> extends ItemSlab {
|
||||
EnumExtraTreeLog[] values;
|
||||
|
||||
public ItemETSlab(V block, V doubleBlock) {
|
||||
super(block, block, doubleBlock);
|
||||
public class ItemETSlab extends ItemSlab {
|
||||
|
||||
public ItemETSlab(BlockETSlab block, BlockETSlab slab, BlockETSlab doubleSlab) {
|
||||
super(block, slab, doubleSlab);
|
||||
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." + BlockETSlab.BLOCK_NAME + "." + values[stack.getMetadata()].getName();
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
BlockETSlab wood = (BlockETSlab) getBlock();
|
||||
int meta = itemstack.getMetadata();
|
||||
IWoodType woodType = wood.getWoodType(meta);
|
||||
return WoodManager.getDisplayName(wood, woodType);
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package binnie.extratrees.block.stairs;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.*;
|
||||
import binnie.extratrees.genetics.WoodAccess;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class BlockETStairs extends BlockStairs implements IWoodKind, IItemModelRegister, IStateMapperRegister {
|
||||
private final boolean fireproof;
|
||||
protected static final int VARIANTS_PER_BLOCK = 1;
|
||||
protected static final PropertyEnumWoodType[] types = PropertyEnumWoodType.create(VARIANTS_PER_BLOCK);
|
||||
public static final String BLOCK_NAME = "stairs";
|
||||
private final int offset;
|
||||
|
||||
public BlockETStairs(int offset, boolean fireproof) {
|
||||
super(WoodAccess.getInstance().getBlock(types[offset].getFirstValue(), WoodBlockKind.PLANKS, fireproof));
|
||||
this.setCreativeTab(Tabs.tabArboriculture);
|
||||
this.setRegistryName(BLOCK_NAME + "." + (fireproof ? "fireproof." : "") + offset);
|
||||
this.offset = offset;
|
||||
this.fireproof = fireproof;
|
||||
this.setUnlocalizedName(types[offset].getFirstValue().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumExtraTreeLog getWoodType(int meta) {
|
||||
return types[offset].getFirstValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WoodBlockKind getWoodKind() {
|
||||
return WoodBlockKind.STAIRS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
|
||||
int meta = getMetaFromState(blockState);
|
||||
EnumExtraTreeLog woodType = getWoodType(meta);
|
||||
return woodType.getHardness();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
|
||||
if (fireproof) {
|
||||
return 0;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, stack -> new ModelResourceLocation(Constants.EXTRA_TREES_MOD_ID + ":" + BLOCK_NAME + "." + getWoodType(0).getMetadata(), "facing=east,half=bottom,shape=straight"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
ExtraTrees.proxy.setCustomStateMapper(BLOCK_NAME + "." + getWoodType(0).getMetadata(), this);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Arrays.stream(types).forEach(type -> {
|
||||
BlockETStairs stairs = new BlockETStairs(type.getGroup(), false) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
BlockETStairs stairs_fireproof = new BlockETStairs(type.getGroup(), true) {
|
||||
@Override
|
||||
public PropertyEnum<EnumExtraTreeLog> getVariant() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
ExtraTrees.proxy.registerItem(new ItemETStairs<>(stairs));
|
||||
ExtraTrees.proxy.registerItem(new ItemETStairs<>(stairs_fireproof));
|
||||
ExtraTrees.proxy.registerBlock(stairs);
|
||||
ExtraTrees.proxy.registerBlock(stairs_fireproof);
|
||||
|
||||
WoodAccess.getInstance().registerWithBlockState(stairs.getDefaultState(), stairs.getWoodKind(), type.getFirstValue(), true);
|
||||
WoodAccess.getInstance().registerWithBlockState(stairs_fireproof.getDefaultState(), stairs.getWoodKind(), type.getFirstValue(), false);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
package binnie.extratrees.block.stairs;
|
||||
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import binnie.extratrees.block.EnumExtraTreeLog;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.arboriculture.blocks.BlockForestryStairs;
|
||||
import forestry.arboriculture.items.ItemBlockWood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemETStairs<V extends BlockETStairs> extends ItemBlock{
|
||||
public class ItemETStairs<B extends BlockForestryStairs<EnumExtraTreeLog>> extends ItemBlockWood<B>{
|
||||
|
||||
public ItemETStairs(final V block) {
|
||||
public ItemETStairs(B block) {
|
||||
super(block);
|
||||
setRegistryName(block.getRegistryName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
B wood = getBlock();
|
||||
int meta = itemstack.getMetadata();
|
||||
IWoodType woodType = wood.getWoodType(meta);
|
||||
return WoodManager.getDisplayName(wood, woodType);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user