mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 03:49:07 +00:00
Fix design blocks
This commit is contained in:
1 parent
7666e96542
commit
172afd0574
20 files changed
+626
-430
No files matched your search
@@ -1,30 +1,60 @@
|
||||
package binnie.extratrees.carpentry;
|
||||
|
||||
import binnie.Constants;
|
||||
import binnie.botany.ceramic.brick.BlockCeramicBrick;
|
||||
import binnie.botany.ceramic.brick.CeramicBrickPair;
|
||||
import binnie.botany.ceramic.brick.TileCeramicBrick;
|
||||
import binnie.core.block.BlockMetadata;
|
||||
import binnie.core.block.IMultipassBlock;
|
||||
import binnie.core.block.TileEntityMetadata;
|
||||
import binnie.core.models.DefaultStateMapper;
|
||||
import binnie.core.models.ModelManager;
|
||||
import binnie.core.models.ModelMutlipass;
|
||||
import binnie.core.util.TileUtil;
|
||||
import binnie.extratrees.api.CarpentryManager;
|
||||
import binnie.extratrees.api.IDesign;
|
||||
import binnie.extratrees.api.IDesignSystem;
|
||||
import binnie.extratrees.api.IToolHammer;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.ISpriteRegister;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.ITextureManager;
|
||||
import forestry.core.blocks.IColoredBlock;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.items.IColoredItem;
|
||||
import forestry.core.models.BlockModelEntry;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BlockDesign extends BlockMetadata implements IMultipassBlock {
|
||||
public abstract class BlockDesign extends BlockMetadata implements IMultipassBlock<Integer>, IColoredBlock, ISpriteRegister, IItemModelRegister, IStateMapperRegister {
|
||||
IDesignSystem designSystem;
|
||||
public static final EnumFacing[] RENDER_DIRECTIONS = new EnumFacing[]{EnumFacing.DOWN, EnumFacing.UP, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH};
|
||||
|
||||
@@ -50,7 +80,7 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
|
||||
final DesignBlock block = blockC.getCarpentryBlock(world, pos);
|
||||
final TileEntityMetadata tile = TileUtil.getTile(world, pos, TileEntityMetadata.class);
|
||||
if (tile != null) {
|
||||
//block.rotate(event.getFace(), item, player, world, pos);
|
||||
block.rotate(event.getFace(), item, player, world, pos);
|
||||
final int meta = block.getBlockMetadata(blockC.getDesignSystem());
|
||||
tile.setTileMetadata(meta, true);
|
||||
}
|
||||
@@ -74,11 +104,6 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
|
||||
return this.designSystem;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public int getRenderType() {
|
||||
// return BinnieCore.multipassRenderID;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getDisplayName(final ItemStack stack) {
|
||||
final DesignBlock block = ModuleCarpentry.getDesignBlock(this.getDesignSystem(), TileEntityMetadata.getItemDamage(stack));
|
||||
@@ -90,27 +115,24 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
|
||||
public DesignBlock getCarpentryBlock(final IBlockAccess world, final BlockPos pos) {
|
||||
return ModuleCarpentry.getDesignBlock(this.getDesignSystem(), TileEntityMetadata.getTileMetadata(world, pos));
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public int colorMultiplier(int p0) {
|
||||
// final DesignBlock block = this.getCarpentryBlock(world, pos);
|
||||
// return (MultipassBlockRenderer.getLayer() > 0) ? block.getSecondaryColour() : block.getPrimaryColour();
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
||||
// @Override
|
||||
// public int colorMultiplier(final int meta) {
|
||||
// final DesignBlock block = ModuleCarpentry.getDesignBlock(this.getDesignSystem(), meta);
|
||||
// return (MultipassBlockRenderer.getLayer() > 0) ? block.getSecondaryColour() : block.getPrimaryColour();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public IIcon getIcon(final int side, final int damage) {
|
||||
// final DesignBlock block = ModuleCarpentry.getDesignBlock(this.getDesignSystem(), damage);
|
||||
// final IIcon icon = (MultipassBlockRenderer.getLayer() > 0) ? block.getSecondaryIcon(this.getDesignSystem(), BlockDesign.RENDER_DIRECTIONS[side]) : block.getPrimaryIcon(this.getDesignSystem(), BlockDesign.RENDER_DIRECTIONS[side]);
|
||||
// return icon;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT_MIPPED;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex) {
|
||||
if(world == null || pos == null){
|
||||
return 0;
|
||||
}
|
||||
DesignBlock block = this.getCarpentryBlock(world, pos);
|
||||
if(tintIndex > 0){
|
||||
return block.getSecondaryColour();
|
||||
}
|
||||
return block.getPrimaryColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
@@ -140,41 +162,95 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
|
||||
return plank1 + (plank2 << 9) + (design << 18);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void registerBlockIcons(final IIconRegister register) {
|
||||
// for (final IDesignSystem system : DesignerManager.instance.getDesignSystems()) {
|
||||
// system.registerIcons(register);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getDroppedMeta(IBlockState state, int tileMetadata) {
|
||||
final DesignBlock block = ModuleCarpentry.getDesignBlock(this.getDesignSystem(), tileMetadata);
|
||||
return block.getItemMetadata(this.getDesignSystem());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EnumBlockRenderType getRenderType(IBlockState state){
|
||||
return EnumBlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
ResourceLocation registryName = getRegistryName();
|
||||
ModelLoader.setCustomStateMapper(this, new DefaultStateMapper(registryName));
|
||||
ModelManager.registerCustomBlockModel(new BlockModelEntry(
|
||||
new ModelResourceLocation(registryName, "normal"),
|
||||
new ModelResourceLocation(registryName, "inventory"),
|
||||
new ModelMutlipass(BlockDesign.class), this));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, new DesignMeshDefinition());
|
||||
}
|
||||
|
||||
private class DesignMeshDefinition implements ItemMeshDefinition{
|
||||
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
return new ModelResourceLocation(getRegistryName(), "inventory");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
return ((IExtendedBlockState)state).withProperty(UnlistedBlockPos.POS, pos).withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int getRenderPasses() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public Object getInventoryKey(ItemStack stack) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Integer getInventoryKey(ItemStack stack) {
|
||||
return TileEntityMetadata.getItemDamage(stack);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public Object getWorldKey(IBlockState state) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Integer getWorldKey(IBlockState state) {
|
||||
IExtendedBlockState extendedState = (IExtendedBlockState) state;
|
||||
IBlockAccess world = extendedState.getValue(UnlistedBlockAccess.BLOCKACCESS);
|
||||
BlockPos pos = extendedState.getValue(UnlistedBlockPos.POS);
|
||||
return TileEntityMetadata.getTileMetadata(world, pos);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public TextureAtlasSprite getSprite(Object key, int pass) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public TextureAtlasSprite getSprite(Integer key, EnumFacing facing, int pass) {
|
||||
DesignBlock block = ModuleCarpentry.getDesignBlock(this.getDesignSystem(), key);
|
||||
|
||||
if(facing == null){
|
||||
return block.getPrimarySprite(getDesignSystem(), BlockDesign.RENDER_DIRECTIONS[0]);
|
||||
}
|
||||
|
||||
if(pass > 0){
|
||||
return block.getSecondarySprite(getDesignSystem(), BlockDesign.RENDER_DIRECTIONS[facing.ordinal()]);
|
||||
}
|
||||
return block.getPrimarySprite(getDesignSystem(), BlockDesign.RENDER_DIRECTIONS[facing.ordinal()]);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerSprites(ITextureManager manager) {
|
||||
for (IDesignSystem system : DesignerManager.instance.getDesignSystems()) {
|
||||
system.registerSprites();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user