Fix design blocks

This commit is contained in:
Nedelosk committed 2017-01-24 21:44:39 +01:00
1 parent 7666e96542
commit 172afd0574
20 files changed
+626 -430

No files matched your search

@@ -53,13 +53,20 @@ public class BlockStainedGlass extends Block implements IBlockMetadata, IColored
return BlockRenderLayer.CUTOUT_MIPPED;
}
@SideOnly(Side.CLIENT)
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
Block block2 = blockAccess.getBlockState(pos.offset(side)).getBlock();
Block block3 = blockAccess.getBlockState(pos).getBlock();
return true/*block3 != this && block3 != ExtraTrees.blockStained && super.shouldSideBeRendered(blockState, blockAccess, pos, side)*/;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
if (blockState != iblockstate) {
return true;
}
if (block == this){
return false;
}
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
@@ -121,12 +128,6 @@ public class BlockStainedGlass extends Block implements IBlockMetadata, IColored
return EnumFlowerColor.get(meta).getColourName() + " Pigmented Glass";
}
@Override
public void dropAsStack(World world, BlockPos pos, ItemStack itemStack) {
spawnAsEntity(world, pos, itemStack);
}
@Override
public void getSubBlocks(final Item itemIn, final CreativeTabs par2CreativeTabs, final List<ItemStack> itemList) {
for (final EnumFlowerColor c : EnumFlowerColor.values()) {
@@ -115,10 +115,11 @@ public class BlockCeramicBrick extends Block implements IMultipassBlock<CeramicB
@SideOnly(Side.CLIENT)
@Override
public void registerStateMapper() {
ModelLoader.setCustomStateMapper(this, new DefaultStateMapper("ceramicBrick"));
ResourceLocation resourceLocation = new ResourceLocation(Constants.BOTANY_MOD_ID, "ceramicBrick");
ModelLoader.setCustomStateMapper(this, new DefaultStateMapper(resourceLocation));
ModelManager.registerCustomBlockModel(new BlockModelEntry(
new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":ceramicBrick", "normal"),
new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":ceramicBrick", "inventory"),
new ModelResourceLocation(resourceLocation, "normal"),
new ModelResourceLocation(resourceLocation, "inventory"),
new ModelMutlipass(BlockCeramicBrick.class), this));
}
@@ -227,7 +228,7 @@ public class BlockCeramicBrick extends Block implements IMultipassBlock<CeramicB
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getSprite(CeramicBrickPair type, int pass) {
public TextureAtlasSprite getSprite(CeramicBrickPair type, EnumFacing facing, int pass) {
return type.getSprite(pass);
}
@@ -28,6 +28,7 @@ import binnie.core.block.ItemMetadata;
import binnie.core.block.TileEntityMetadata;
import binnie.core.item.IItemMiscProvider;
import binnie.core.item.ItemMisc;
import binnie.extratrees.carpentry.ItemDesign;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
@@ -90,7 +91,7 @@ public class ModuleGardening implements IInitializable {
Botany.proxy.registerBlock(Botany.stained, new ItemMetadata(Botany.stained));
// BinnieCore.proxy.registerCustomItemRenderer(Item.getItemFromBlock(Botany.stained), new ItemMetadataRenderer());
Botany.ceramicTile = new BlockCeramicPatterned();
Botany.proxy.registerBlock(Botany.ceramicTile, new ItemMetadata(Botany.ceramicTile));
Botany.proxy.registerBlock(Botany.ceramicTile, new ItemDesign(Botany.ceramicTile));
Botany.ceramicBrick = new BlockCeramicBrick();
Botany.proxy.registerBlock(Botany.ceramicBrick, new ItemCeramicBrick(Botany.ceramicBrick));
GameRegistry.registerTileEntity(TileCeramicBrick.class, "");
@@ -1,8 +1,11 @@
package binnie.core.block;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -17,8 +20,8 @@ public interface IMultipassBlock<K> {
K getWorldKey(IBlockState state);
/**
* pass -1 = particle Sprite
* pass -1 and facing null = particle Sprite
*/
@SideOnly(Side.CLIENT)
TextureAtlasSprite getSprite(K key, int pass);
TextureAtlasSprite getSprite(K key, @Nullable EnumFacing facing, int pass);
}
@@ -1,5 +1,6 @@
package binnie.core.block;
import binnie.core.network.packet.MessageMetadata;
import binnie.core.network.packet.PacketMetadata;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -27,6 +28,11 @@ public class TileEntityMetadata extends TileEntity {
}
return true;
}
@Override
public NBTTagCompound getUpdateTag() {
return writeToNBT(new NBTTagCompound());
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
@@ -36,12 +42,11 @@ public class TileEntityMetadata extends TileEntity {
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt) {
NBTTagCompound nbt2 = super.writeToNBT(nbt);
nbt2.setInteger("meta", this.meta);
return nbt2;
super.writeToNBT(nbt);
nbt.setInteger("meta", this.meta);
return nbt;
}
public int getTileMetadata() {
return this.meta;
}
@@ -59,6 +64,10 @@ public class TileEntityMetadata extends TileEntity {
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
if(pkt instanceof PacketMetadata){
setTileMetadata(((PacketMetadata) pkt).getMetadata(), true);
}
}
@Override
@@ -4,18 +4,19 @@ import binnie.Constants;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.util.ResourceLocation;
public class DefaultStateMapper extends StateMapperBase {
private String modelName;
private ResourceLocation resourceLocation;
public DefaultStateMapper(String modelName) {
this.modelName = modelName;
public DefaultStateMapper(ResourceLocation resourceLocation) {
this.resourceLocation = resourceLocation;
}
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":" + modelName, "normal");
return new ModelResourceLocation(resourceLocation, "normal");
}
}
@@ -7,7 +7,9 @@ import forestry.core.models.baker.ModelBaker;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -32,12 +34,16 @@ public class ModelMutlipass<B extends Block & IMultipassBlock<K>, K> extends Mod
@Override
protected void bakeBlock(B block, K key, IModelBaker baker, boolean inventory) {
for (int pass = 0; pass < block.getRenderPasses(); pass++) {
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, block.getSprite(key, pass), pass);
TextureAtlasSprite[] sprites = new TextureAtlasSprite[6];
for(EnumFacing facing : EnumFacing.VALUES){
sprites[facing.ordinal()] = block.getSprite(key, facing, pass);
}
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, sprites, pass);
}
// Set the particle sprite
//TODO: Adding a preaking sprite
baker.setParticleSprite(block.getSprite(key, 0));
baker.setParticleSprite(block.getSprite(key, null, 0));
}
@Override
@@ -28,4 +28,8 @@ public class PacketMetadata extends SPacketUpdateTileEntity {
metadata = buf.readInt();
}
public int getMetadata() {
return metadata;
}
}
@@ -1,5 +1,9 @@
package binnie.extratrees.api;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface ILayout {
IPattern getPattern();
@@ -15,7 +19,9 @@ public interface ILayout {
ILayout invert();
// IIcon getPrimaryIcon(final IDesignSystem p0);
//
// IIcon getSecondaryIcon(final IDesignSystem p0);
@SideOnly(Side.CLIENT)
TextureAtlasSprite getPrimarySprite(IDesignSystem system);
@SideOnly(Side.CLIENT)
TextureAtlasSprite getSecondarySprite(IDesignSystem system);
}
@@ -1,13 +1,19 @@
package binnie.extratrees.api;
public interface IPattern {
// IIcon getPrimaryIcon(final IDesignSystem p0);
//
// IIcon getSecondaryIcon(final IDesignSystem p0);
import forestry.api.core.ISpriteRegister;
import forestry.api.core.ITextureManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface IPattern extends ISpriteRegister {
@SideOnly(Side.CLIENT)
TextureAtlasSprite getPrimarySprite(IDesignSystem system);
@SideOnly(Side.CLIENT)
TextureAtlasSprite getSecondarySprite(IDesignSystem system);
ILayout getRotation();
ILayout getHorizontalFlip();
// void registerIcons(final IIconRegister p0);
}
@@ -239,10 +239,6 @@ public class ModuleBlocks implements IInitializable {
@Override
public void init() {
// ExtraTrees.fenceID = RenderingRegistry.getNextAvailableRenderId();
// RenderingRegistry.registerBlockHandler(new FenceRenderer());
// ExtraTrees.stairsID = RenderingRegistry.getNextAvailableRenderId();
// RenderingRegistry.registerBlockHandler(new StairsRenderer());
// ExtraTrees.doorRenderId = RenderingRegistry.getNextAvailableRenderId();
// RenderingRegistry.registerBlockHandler(new DoorBlockRenderer());
// RenderingRegistry.registerBlockHandler(new HedgeRenderer());
@@ -3,9 +3,13 @@ package binnie.extratrees.carpentry;
import binnie.Binnie;
import binnie.core.block.TileEntityMetadata;
import binnie.extratrees.ExtraTrees;
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.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.List;
@@ -97,16 +101,14 @@ public class BlockCarpentryPanel extends BlockCarpentry {
// return ModuleCarpentry.getCarpentryPanel(this.getDesignSystem(), TileEntityMetadata.getTileMetadata(world, x, y, z));
// }
// public static boolean isValidPanelPlacement(final World world, final int x, final int y, final int z, final ForgeDirection facing) {
// if (facing == ForgeDirection.UNKNOWN) {
// return false;
// }
// final int bx = x - facing.offsetX;
// final int by = y - facing.offsetY;
// final int bz = z - facing.offsetZ;
// final Block block = world.getBlock(bx, by, bz);
// return block != null && block.isSideSolid(world, bx, by, bz, facing);
// }
public static boolean isValidPanelPlacement(World world, BlockPos pos, EnumFacing facing) {
if (facing == null) {
return false;
}
pos = pos.offset(facing, -1);
IBlockState state = world.getBlockState(pos);
return state != null && state.isSideSolid(world, pos, facing);
}
//
// @Override
// public int getPlacedMeta(final ItemStack item, final World world, final int x, final int y, final int z, final ForgeDirection clickedBlock) {
@@ -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();
}
}
}
@@ -1,11 +1,21 @@
package binnie.extratrees.carpentry;
import binnie.Binnie;
import binnie.botany.Botany;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.api.IDesign;
import forestry.api.core.Tabs;
import net.minecraft.block.Block;
import net.minecraft.block.BlockGlass;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Random;
@@ -20,30 +30,37 @@ public class BlockStainedDesign extends BlockDesign {
public int quantityDropped(final Random p_149745_1_) {
return 0;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
// @Override
// public boolean isOpaqueCube() {
// return false;
// }
//
// @Override
// public boolean renderAsNormalBlock() {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public int getRenderBlockPass() {
// return 1;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public boolean shouldSideBeRendered(final IBlockAccess p_149646_1_, final int p_149646_2_, final int p_149646_3_, final int p_149646_4_, final int p_149646_5_) {
// final Block block2 = p_149646_1_.getBlock(p_149646_2_ - Facing.offsetsXForSide[p_149646_5_], p_149646_3_ - Facing.offsetsYForSide[p_149646_5_], p_149646_4_ - Facing.offsetsZForSide[p_149646_5_]);
// final Block block3 = p_149646_1_.getBlock(p_149646_2_, p_149646_3_, p_149646_4_);
// return block3 != this && block3 != Botany.stained && super.shouldSideBeRendered(p_149646_1_, p_149646_2_, p_149646_3_, p_149646_4_, p_149646_5_);
// }
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderPasses() {
return 1;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
if (blockState != iblockstate) {
return true;
}
if (block == this){
return false;
}
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
public ItemStack getCreativeStack(final IDesign design) {
@@ -3,10 +3,18 @@ package binnie.extratrees.carpentry;
import binnie.extratrees.api.IDesign;
import binnie.extratrees.api.IDesignMaterial;
import binnie.extratrees.api.IDesignSystem;
import binnie.extratrees.api.ILayout;
import binnie.extratrees.api.IToolHammer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Rotations;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class DesignBlock {
IDesign design;
@@ -124,253 +132,270 @@ public class DesignBlock {
}
}
}
private static final int[][] ROTATION_MATRIX = {
{0, 1, 4, 5, 3, 2, 6},
{0, 1, 5, 4, 2, 3, 6},
{5, 4, 2, 3, 0, 1, 6},
{4, 5, 2, 3, 1, 0, 6},
{2, 3, 1, 0, 4, 5, 6},
{3, 2, 0, 1, 4, 5, 6},
{0, 1, 2, 3, 4, 5, 6},
};
public EnumFacing getRotation(EnumFacing facing, EnumFacing axis) {
return getNewFacing(ROTATION_MATRIX[axis.ordinal()][facing.ordinal()]);
}
// public ILayout getLayout(EnumFacing dir) {
// EnumFacing adjustedDir;
// dir = (adjustedDir = dir.getRotation(EnumFacing.DOWN));
// switch (this.getFacing()) {
// case DOWN: {
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// break;
// }
// case EAST: {
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// adjustedDir = adjustedDir.getRotation(EnumFacing.NORTH);
// break;
// }
// case NORTH: {
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// adjustedDir = adjustedDir.getRotation(EnumFacing.SOUTH);
// adjustedDir = adjustedDir.getRotation(EnumFacing.SOUTH);
// break;
// }
// case SOUTH: {
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// break;
// }
// case WEST: {
// adjustedDir = adjustedDir.getRotation(EnumFacing.EAST);
// adjustedDir = adjustedDir.getRotation(EnumFacing.SOUTH);
// break;
// }
// }
// for (int i = 0; i < this.rotation; ++i) {
// adjustedDir = adjustedDir.getRotation(EnumFacing.DOWN);
// }
// ILayout layout = null;
// switch (adjustedDir) {
// case EAST: {
// layout = this.getDesign().getEastPattern();
// break;
// }
// case NORTH: {
// layout = this.getDesign().getNorthPattern();
// break;
// }
// case SOUTH: {
// layout = this.getDesign().getSouthPattern();
// break;
// }
// case WEST: {
// layout = this.getDesign().getWestPattern();
// break;
// }
// case DOWN: {
// layout = this.getDesign().getBottomPattern();
// break;
// }
// default: {
// layout = this.getDesign().getTopPattern();
// break;
// }
// }
// Label_1107: {
// switch (this.getFacing()) {
// case UP: {
// if (dir == EnumFacing.DOWN || dir == EnumFacing.UP) {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateRight();
// }
// break;
// }
// break;
// }
// case DOWN: {
// switch (dir) {
// case UP:
// case DOWN: {
// layout = layout.flipVertical();
// break;
// }
// case EAST:
// case NORTH:
// case SOUTH:
// case WEST: {
// layout = layout.rotateRight().rotateRight();
// break;
// }
// }
// if (dir == EnumFacing.DOWN || dir == EnumFacing.UP) {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateLeft();
// }
// break;
// }
// break;
// }
// case EAST: {
// switch (dir) {
// case SOUTH:
// case UP: {
// layout = layout.rotateRight();
// break;
// }
// case NORTH: {
// layout = layout.rotateLeft();
// break;
// }
// case DOWN: {
// layout = layout.rotateLeft().flipHorizontal();
// break;
// }
// case WEST: {
// layout = layout.flipHorizontal();
// break;
// }
// }
// if (dir == EnumFacing.EAST) {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateRight();
// }
// }
// if (dir == EnumFacing.WEST) {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateLeft();
// }
// break;
// }
// break;
// }
// case WEST: {
// switch (dir) {
// case NORTH: {
// layout = layout.rotateRight();
// break;
// }
// case SOUTH:
// case UP: {
// layout = layout.rotateLeft();
// break;
// }
// case DOWN: {
// layout = layout.rotateLeft().flipVertical();
// break;
// }
// case EAST: {
// layout = layout.flipHorizontal();
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateLeft();
// }
// break;
// }
// case WEST: {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateRight();
// }
// break;
// }
// }
// break;
// }
// case NORTH: {
// switch (dir) {
// case WEST: {
// layout = layout.rotateLeft();
// break Label_1107;
// }
// case EAST: {
// layout = layout.rotateRight();
// break Label_1107;
// }
// case DOWN: {
// layout = layout.flipHorizontal();
// break Label_1107;
// }
// case SOUTH: {
// layout = layout.flipHorizontal();
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateLeft();
// }
// break Label_1107;
// }
// case NORTH: {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateRight();
// }
// break Label_1107;
// }
// default: {
// break Label_1107;
// }
// }
//
// }
// case SOUTH: {
// switch (dir) {
// case EAST: {
// layout = layout.rotateLeft();
// break Label_1107;
// }
// case WEST: {
// layout = layout.rotateRight();
// break Label_1107;
// }
// case UP: {
// layout = layout.rotateRight().rotateRight();
// break Label_1107;
// }
// case DOWN: {
// layout = layout.flipVertical();
// break Label_1107;
// }
// case NORTH: {
// layout = layout.flipHorizontal();
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateLeft();
// }
// break Label_1107;
// }
// case SOUTH: {
// for (int j = 0; j < this.rotation; ++j) {
// layout = layout.rotateRight();
// }
// break Label_1107;
// }
// default: {
// break Label_1107;
// }
// }
//
// }
// }
// }
// return layout;
// }
//
// public IIcon getPrimaryIcon(final IDesignSystem system, final EnumFacing dir) {
// final ILayout l = this.getLayout(dir);
// return (l == null) ? null : l.getPrimaryIcon(system);
// }
//
// public IIcon getSecondaryIcon(final IDesignSystem system, final EnumFacing dir) {
// final ILayout l = this.getLayout(dir);
// return (l == null) ? null : l.getSecondaryIcon(system);
// }
//
// public IIcon getIcon(final IDesignSystem system, final boolean secondary, final EnumFacing dir) {
// return secondary ? this.getSecondaryIcon(system, dir) : this.getPrimaryIcon(system, dir);
// }
public ILayout getLayout(EnumFacing facing) {
EnumFacing adjustedFacing;
facing = (adjustedFacing = getRotation(facing, EnumFacing.DOWN));
switch (this.getFacing()) {
case DOWN: {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
break;
}
case EAST: {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
adjustedFacing = getRotation(adjustedFacing, EnumFacing.NORTH);
break;
}
case NORTH: {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
adjustedFacing = getRotation(adjustedFacing, EnumFacing.SOUTH);
adjustedFacing = getRotation(adjustedFacing, EnumFacing.SOUTH);
break;
}
case SOUTH: {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
break;
}
case WEST: {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.EAST);
adjustedFacing = getRotation(adjustedFacing, EnumFacing.SOUTH);
break;
}
}
for (int i = 0; i < this.rotation; ++i) {
adjustedFacing = getRotation(adjustedFacing, EnumFacing.DOWN);
}
ILayout layout = null;
switch (adjustedFacing) {
case EAST: {
layout = this.getDesign().getEastPattern();
break;
}
case NORTH: {
layout = this.getDesign().getNorthPattern();
break;
}
case SOUTH: {
layout = this.getDesign().getSouthPattern();
break;
}
case WEST: {
layout = this.getDesign().getWestPattern();
break;
}
case DOWN: {
layout = this.getDesign().getBottomPattern();
break;
}
default: {
layout = this.getDesign().getTopPattern();
break;
}
}
LAYOUTS: {
switch (this.getFacing()) {
case UP: {
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateRight();
}
break;
}
break;
}
case DOWN: {
switch (facing) {
case UP:
case DOWN: {
layout = layout.flipVertical();
break;
}
case EAST:
case NORTH:
case SOUTH:
case WEST: {
layout = layout.rotateRight().rotateRight();
break;
}
}
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateLeft();
}
break;
}
break;
}
case EAST: {
switch (facing) {
case SOUTH:
case UP: {
layout = layout.rotateRight();
break;
}
case NORTH: {
layout = layout.rotateLeft();
break;
}
case DOWN: {
layout = layout.rotateLeft().flipHorizontal();
break;
}
case WEST: {
layout = layout.flipHorizontal();
break;
}
}
if (facing == EnumFacing.EAST) {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateRight();
}
}
if (facing == EnumFacing.WEST) {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateLeft();
}
break;
}
break;
}
case WEST: {
switch (facing) {
case NORTH: {
layout = layout.rotateRight();
break;
}
case SOUTH:
case UP: {
layout = layout.rotateLeft();
break;
}
case DOWN: {
layout = layout.rotateLeft().flipVertical();
break;
}
case EAST: {
layout = layout.flipHorizontal();
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateLeft();
}
break;
}
case WEST: {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateRight();
}
break;
}
}
break;
}
case NORTH: {
switch (facing) {
case WEST: {
layout = layout.rotateLeft();
break LAYOUTS;
}
case EAST: {
layout = layout.rotateRight();
break LAYOUTS;
}
case DOWN: {
layout = layout.flipHorizontal();
break LAYOUTS;
}
case SOUTH: {
layout = layout.flipHorizontal();
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateLeft();
}
break LAYOUTS;
}
case NORTH: {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateRight();
}
break LAYOUTS;
}
default: {
break LAYOUTS;
}
}
}
case SOUTH: {
switch (facing) {
case EAST: {
layout = layout.rotateLeft();
break LAYOUTS;
}
case WEST: {
layout = layout.rotateRight();
break LAYOUTS;
}
case UP: {
layout = layout.rotateRight().rotateRight();
break LAYOUTS;
}
case DOWN: {
layout = layout.flipVertical();
break LAYOUTS;
}
case NORTH: {
layout = layout.flipHorizontal();
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateLeft();
}
break LAYOUTS;
}
case SOUTH: {
for (int j = 0; j < this.rotation; ++j) {
layout = layout.rotateRight();
}
break LAYOUTS;
}
default: {
break LAYOUTS;
}
}
}
}
}
return layout;
}
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getPrimarySprite(IDesignSystem system, EnumFacing facing) {
ILayout layout = this.getLayout(facing);
return (layout == null) ? null : layout.getPrimarySprite(system);
}
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getSecondarySprite(IDesignSystem system, EnumFacing facing) {
ILayout layout = this.getLayout(facing);
return (layout == null) ? null : layout.getSecondarySprite(system);
}
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getSprite(IDesignSystem system, boolean secondary, EnumFacing facing) {
return secondary ? this.getSecondarySprite(system, facing) : this.getPrimarySprite(system, facing);
}
public EnumFacing getFacing() {
return this.facing;
@@ -380,41 +405,45 @@ public class DesignBlock {
return this.rotation;
}
public void rotate(final int face, final ItemStack hammer, final EntityPlayer player, final World world, final int x, final int y, final int z) {
// final EnumFacing dir = EnumFacing.getOrientation(face);
// final IToolHammer hammerI = (IToolHammer) hammer.getItem();
// if (player.isSneaking()) {
// if (this.panel) {
// EnumFacing newFacing = this.getFacing();
// do {
// newFacing = EnumFacing.getOrientation(newFacing.ordinal() + 1);
// if (newFacing == EnumFacing.UNKNOWN) {
// newFacing = EnumFacing.DOWN;
// }
// } while (newFacing != this.getFacing() && !BlockCarpentryPanel.isValidPanelPlacement(world, x, y, z, newFacing));
// if (newFacing != this.getFacing()) {
// hammerI.onHammerUsed(hammer, player);
// }
// this.setFacing(newFacing);
// }
// else {
// if (dir != this.getFacing()) {
// hammerI.onHammerUsed(hammer, player);
// }
// this.setFacing(dir);
// }
// }
// else {
// ++this.rotation;
// hammerI.onHammerUsed(hammer, player);
// }
// if (this.rotation > 3) {
// this.rotation = 0;
// }
// if (this.rotation < 0) {
// this.rotation = 3;
// }
public void rotate(EnumFacing facing, final ItemStack hammer, final EntityPlayer player, final World world, BlockPos pos) {
final IToolHammer hammerI = (IToolHammer) hammer.getItem();
if (player.isSneaking()) {
if (this.panel) {
EnumFacing newFacing = this.getFacing();
do {
newFacing = getNewFacing(newFacing.ordinal() + 1);
} while (newFacing != this.getFacing() && !BlockCarpentryPanel.isValidPanelPlacement(world, pos, newFacing));
if (newFacing != this.getFacing()) {
hammerI.onHammerUsed(hammer, player);
}
this.setFacing(newFacing);
}
else {
if (facing != this.getFacing()) {
hammerI.onHammerUsed(hammer, player);
}
this.setFacing(facing);
}
}
else {
++this.rotation;
hammerI.onHammerUsed(hammer, player);
}
if (this.rotation > 3) {
this.rotation = 0;
}
if (this.rotation < 0) {
this.rotation = 3;
}
}
private EnumFacing getNewFacing(int index){
if (index >= 0 && index < EnumFacing.VALUES.length)
{
return EnumFacing.VALUES[index];
}
return EnumFacing.DOWN;
}
public void setFacing(final EnumFacing facing) {
this.facing = facing;
@@ -152,8 +152,8 @@ public enum DesignSystem implements IDesignSystem {
@Override
public void registerSprites() {
for (final EnumPattern pattern : EnumPattern.values()) {
this.primary.put(pattern.ordinal(), TextureManager.registerSprite(new ResourceLocation(getMod().getModID(), getTexturePath() + "/" + pattern.toString().toLowerCase() + ".0")));
this.secondary.put(pattern.ordinal(), TextureManager.registerSprite(new ResourceLocation(getMod().getModID(), getTexturePath() + "/" + pattern.toString().toLowerCase() + ".1")));
this.primary.put(pattern.ordinal(), TextureManager.registerSprite(new ResourceLocation(getMod().getModID(), "blocks/" + getTexturePath() + "/" + pattern.toString().toLowerCase() + ".0")));
this.secondary.put(pattern.ordinal(), TextureManager.registerSprite(new ResourceLocation(getMod().getModID(), "blocks/" + getTexturePath() + "/" + pattern.toString().toLowerCase() + ".1")));
}
}
@@ -1,7 +1,12 @@
package binnie.extratrees.carpentry;
import binnie.extratrees.api.IDesignSystem;
import binnie.extratrees.api.ILayout;
import binnie.extratrees.api.IPattern;
import forestry.api.core.ITextureManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public enum EnumPattern implements IPattern {
Blank,
@@ -289,10 +294,11 @@ public enum EnumPattern implements IPattern {
setupEdgedPattern(l, t, r, b);
}
// @Override
// public IIcon getPrimaryIcon(final IDesignSystem system) {
// return system.getPrimaryIcon(this);
// }
@SideOnly(Side.CLIENT)
@Override
public TextureAtlasSprite getPrimarySprite(IDesignSystem system) {
return system.getPrimarySprite(this);
}
private static void setupRotation(final EnumPattern t, final EnumPattern r, final EnumPattern b, final EnumPattern l) {
setupEdgedPattern(l, t, r, b);
@@ -303,10 +309,11 @@ public enum EnumPattern implements IPattern {
pattern.horizontalFlip = Layout.get(this, inverted);
}
// @Override
// public IIcon getSecondaryIcon(final IDesignSystem system) {
// return system.getSecondaryIcon(this);
// }
@SideOnly(Side.CLIENT)
@Override
public TextureAtlasSprite getSecondarySprite(IDesignSystem system) {
return system.getSecondarySprite(this);
}
@Override
public ILayout getRotation() {
@@ -321,10 +328,10 @@ public enum EnumPattern implements IPattern {
protected void setLeftRotation(final EnumPattern pattern, final boolean inverted) {
this.leftRotation = Layout.get(pattern, inverted);
}
// @Override
// public void registerIcons(final IIconRegister register) {
// }
@Override
public void registerSprites(ITextureManager manager) {
}
public ILayout layout() {
return this.layout(false);
@@ -0,0 +1,27 @@
package binnie.extratrees.carpentry;
import binnie.core.block.ItemMetadata;
import binnie.core.block.TileEntityMetadata;
import forestry.core.items.IColoredItem;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemDesign extends ItemMetadata implements IColoredItem{
public ItemDesign(BlockDesign block) {
super(block);
}
@SideOnly(Side.CLIENT)
@Override
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
DesignBlock block = ModuleCarpentry.getDesignBlock(((BlockDesign)this.block).getDesignSystem(), TileEntityMetadata.getItemDamage(stack));
if(tintIndex > 0){
return block.getSecondaryColour();
}
return block.getPrimaryColour();
}
}
@@ -1,7 +1,11 @@
package binnie.extratrees.carpentry;
import binnie.extratrees.api.IDesignSystem;
import binnie.extratrees.api.ILayout;
import binnie.extratrees.api.IPattern;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class Layout implements ILayout {
IPattern pattern;
@@ -50,15 +54,17 @@ public class Layout implements ILayout {
return this.newLayout(this.pattern.getHorizontalFlip().rotateLeft().rotateLeft());
}
// @Override
// public IIcon getPrimaryIcon(final IDesignSystem system) {
// return this.inverted ? this.pattern.getSecondaryIcon(system) : this.pattern.getPrimaryIcon(system);
// }
//
// @Override
// public IIcon getSecondaryIcon(final IDesignSystem system) {
// return this.inverted ? this.pattern.getPrimaryIcon(system) : this.pattern.getSecondaryIcon(system);
// }
@SideOnly(Side.CLIENT)
@Override
public TextureAtlasSprite getPrimarySprite(IDesignSystem system) {
return this.inverted ? this.pattern.getSecondarySprite(system) : this.pattern.getPrimarySprite(system);
}
@SideOnly(Side.CLIENT)
@Override
public TextureAtlasSprite getSecondarySprite(IDesignSystem system) {
return this.inverted ? this.pattern.getPrimarySprite(system) : this.pattern.getSecondarySprite(system);
}
@Override
public ILayout invert() {
@@ -3,6 +3,7 @@ package binnie.extratrees.carpentry;
import binnie.core.IInitializable;
import binnie.core.block.ItemMetadata;
import binnie.core.block.TileEntityMetadata;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.api.CarpentryManager;
import binnie.extratrees.api.IDesign;
import binnie.extratrees.api.IDesignMaterial;
@@ -23,12 +24,9 @@ public class ModuleCarpentry implements IInitializable {
blockCarpentry = new BlockCarpentry("carpentry");
blockPanel = new BlockCarpentryPanel();
blockStained = new BlockStainedDesign();
GameRegistry.register(blockCarpentry);
GameRegistry.register(new ItemMetadata(blockCarpentry).setRegistryName(blockCarpentry.getRegistryName()));
GameRegistry.register(blockPanel);
GameRegistry.register(new ItemMetadata(blockPanel).setRegistryName(blockPanel.getRegistryName()));
GameRegistry.register(blockStained);
GameRegistry.register(new ItemMetadata(blockStained).setRegistryName(blockStained.getRegistryName()));
ExtraTrees.proxy.registerBlock(blockCarpentry, new ItemDesign(blockCarpentry));
ExtraTrees.proxy.registerBlock(blockPanel, new ItemDesign(blockPanel));
ExtraTrees.proxy.registerBlock(blockStained, new ItemDesign(blockPanel));
//BinnieCore.proxy.registerCustomItemRenderer(Item.getItemFromBlock(ExtraTrees.blockCarpentry), new MultipassItemRenderer());
//BinnieCore.proxy.registerCustomItemRenderer(Item.getItemFromBlock(ExtraTrees.blockStained), new MultipassItemRenderer());