Jump to content

Cliff122

Members
  • Posts

    14
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Cliff122's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hi! This is a very simple question, but I couldn't find the answer to it anywhere. I know you can set the text on the title of normal chests in the TileEntity class like this: public String getName() { return this.hasCustomName() ? this.customName : "container.spruceChest"; } But I can't figure out how to do this for the large chests.
  2. Okay, does anyone know anything about these other rendering glitches and/or how to fix them?
  3. Okay, thanks for the help! I got the item rendering working by adding this to my TileEntityRenderer-class. if (te == null) { te = new TileEntitySpruceChest(); } Is that a good solution or are there any better? Also, another model related issue. Depending on the order I place them down the models glitch out when I place my custom chest next to vanilla chests. All the chests and hitboxes work as intended, only the rendering is weird. Pictures Could it have anything to do with the fact that I am extending vanilla classes?
  4. Ok, that seems so be on the right track. I looked up this example on how to use it and did basically the same like this ForgeHooksClient.registerTESRItemStack(Item.getItemFromBlock(MBBlocks.spruce_chest), 0, TileEntitySpruceChest.class); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MBBlocks.spruce_chest), 0, new ModelResourceLocation("mb:spruce_chest", "normal")); But when it tries to render, the game crashes and gives me this log: https://gist.github.com/anonymous/5ce5864ac4bd325f1e7be842b1a91dbf
  5. Hi! I've been tinkering with making custom chests by looking at and copying vanilla code. So far I have managed to make it work and look like a vanilla chest while placed in the world, however in the inventory and hand it has the black and pink error-texture. I have tried copying the vanilla item model, but that alone doesn't do anything. I suspect I have to use some kind of special renderer but I can't figure out how. This is my current code, if you need any other classes just ask. TileEntitySpruceChest.java package nu.aksberg.mb.tileentity; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import nu.aksberg.mb.block.SpruceChestBlock; public class TileEntitySpruceChest extends TileEntityChest{ private SpruceChestBlock.Type cachedChestType; public TileEntitySpruceChest() { } public TileEntitySpruceChest(SpruceChestBlock.Type p_i46677_1_) { this.cachedChestType = p_i46677_1_; } @SuppressWarnings("incomplete-switch") private void func_174910_a(TileEntitySpruceChest chestTe, EnumFacing side) { if (chestTe.isInvalid()) { this.adjacentChestChecked = false; } else if (this.adjacentChestChecked) { switch (side) { case NORTH: if (this.adjacentChestZNeg != chestTe) { this.adjacentChestChecked = false; } break; case SOUTH: if (this.adjacentChestZPos != chestTe) { this.adjacentChestChecked = false; } break; case EAST: if (this.adjacentChestXPos != chestTe) { this.adjacentChestChecked = false; } break; case WEST: if (this.adjacentChestXNeg != chestTe) { this.adjacentChestChecked = false; } } } } protected TileEntitySpruceChest getAdjacentChest(EnumFacing side) { BlockPos blockpos = this.pos.offset(side); if (this.isChestAt(blockpos)) { TileEntity tileentity = this.worldObj.getTileEntity(blockpos); if (tileentity instanceof TileEntitySpruceChest) { TileEntitySpruceChest tileentitychest = (TileEntitySpruceChest)tileentity; tileentitychest.func_174910_a(this, side.getOpposite()); return tileentitychest; } } return null; } private boolean isChestAt(BlockPos posIn) { if (this.worldObj == null) { return false; } else { Block block = this.worldObj.getBlockState(posIn).getBlock(); return block instanceof SpruceChestBlock && ((SpruceChestBlock)block).chestType == this.getChestType(); } } @Override public void closeInventory(EntityPlayer player) { if (!player.isSpectator() && this.getBlockType() instanceof SpruceChestBlock) { --this.numPlayersUsing; this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing); this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType()); this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); } } @Override public SpruceChestBlock.Type getChestType() { if (this.cachedChestType == null) { if (this.worldObj == null || !(this.getBlockType() instanceof SpruceChestBlock)) { return SpruceChestBlock.Type.BASIC; } this.cachedChestType = ((SpruceChestBlock)this.getBlockType()).chestType; } return this.cachedChestType; } } TileEntitySpruceChestRenderer.java package nu.aksberg.mb.client.renderer.tilentity; import java.util.Calendar; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.client.model.ModelChest; import net.minecraft.client.model.ModelLargeChest; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntityChestRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.ResourceLocation; public class TileEntitySpruceChestRenderer extends TileEntitySpecialRenderer<TileEntityChest> { private static final ResourceLocation textureTrappedDouble = new ResourceLocation("textures/entity/chest/trapped_double.png"); private static final ResourceLocation textureChristmasDouble = new ResourceLocation("textures/entity/chest/christmas_double.png"); private static final ResourceLocation textureNormalDouble = new ResourceLocation("mb:textures/entity/chest/spruce_double.png"); private static final ResourceLocation textureTrapped = new ResourceLocation("textures/entity/chest/trapped.png"); private static final ResourceLocation textureChristmas = new ResourceLocation("textures/entity/chest/christmas.png"); private static final ResourceLocation textureNormal = new ResourceLocation("mb:textures/entity/chest/spruce.png"); private ModelChest simpleChest = new ModelChest(); private ModelChest largeChest = new ModelLargeChest(); private boolean isChristmas; public TileEntitySpruceChestRenderer() { Calendar calendar = Calendar.getInstance(); if (calendar.get(2) + 1 == 12 && calendar.get(5) >= 24 && calendar.get(5) <= 26) { this.isChristmas = true; } } public void renderTileEntityAt(TileEntityChest te, double x, double y, double z, float partialTicks, int destroyStage) { GlStateManager.enableDepth(); GlStateManager.depthFunc(515); GlStateManager.depthMask(true); int i; if (!te.hasWorldObj()) { i = 0; } else { Block block = te.getBlockType(); i = te.getBlockMetadata(); if (block instanceof BlockChest && i == 0) { ((BlockChest)block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos())); i = te.getBlockMetadata(); } te.checkForAdjacentChests(); } if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) { ModelChest modelchest; if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) { modelchest = this.simpleChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(4.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else if (this.isChristmas) { this.bindTexture(textureChristmas); } else if (te.getChestType() == BlockChest.Type.TRAP) { this.bindTexture(textureTrapped); } else { this.bindTexture(textureNormal); } } else { modelchest = this.largeChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(8.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else if (this.isChristmas) { this.bindTexture(textureChristmasDouble); } else if (te.getChestType() == BlockChest.Type.TRAP) { this.bindTexture(textureTrappedDouble); } else { this.bindTexture(textureNormalDouble); } } GlStateManager.pushMatrix(); GlStateManager.enableRescaleNormal(); if (destroyStage < 0) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); } GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F); GlStateManager.scale(1.0F, -1.0F, -1.0F); GlStateManager.translate(0.5F, 0.5F, 0.5F); int j = 0; if (i == 2) { j = 180; } if (i == 3) { j = 0; } if (i == 4) { j = 90; } if (i == 5) { j = -90; } if (i == 2 && te.adjacentChestXPos != null) { GlStateManager.translate(1.0F, 0.0F, 0.0F); } if (i == 5 && te.adjacentChestZPos != null) { GlStateManager.translate(0.0F, 0.0F, -1.0F); } GlStateManager.rotate((float)j, 0.0F, 1.0F, 0.0F); GlStateManager.translate(-0.5F, -0.5F, -0.5F); float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks; if (te.adjacentChestZNeg != null) { float f1 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks; if (f1 > f) { f = f1; } } if (te.adjacentChestXNeg != null) { float f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks; if (f2 > f) { f = f2; } } f = 1.0F - f; f = 1.0F - f * f * f; modelchest.chestLid.rotateAngleX = -(f * ((float)Math.PI / 2F)); modelchest.renderAll(); GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (destroyStage >= 0) { GlStateManager.matrixMode(5890); GlStateManager.popMatrix(); GlStateManager.matrixMode(5888); } } } }
  6. Oops, must have misspelled the title. I meant blocks of course. Anyway, that worked! Thank you once again Choonster, your quick replies and detailed explanations are really helpful.
  7. Hi! Just a quick question here, I have implemented some custom signs in my minecraft mod and I was wondering if there is any way to "hide" the wallsign and standing sign blocks from commands like /give and such, like the vanilla signblocks.
  8. Create an anonymous class that extends StateMapperBase and override the getModelResourceLocation method to return a ModelResourceLocation pointing to the variant in your blockstates file. In this case, use the ModelResourceLocation(String resourceName, String variant) constructor with "sbm:spruce_sign" as the resource name (i.e. assets/sbm/blockstates/spruce_sign.json) and "normal" as the variant. Call ModelLoader.setCustomStateMapper from your client proxy in preInit with your Block as the first argument and this anonymous class as the second argument. I do something similar for my fluid blocks here. Okay, everything seems to work now! Thanks a bunch for all the help, I wouldn't have been able to do this without it.
  9. I have made a model file called spruce_sign.json: { "parent": "block/cube_all", "textures": { "particle": "blocks/planks_spruce" } } and a blockstate also called spruce_sign.json: { "variants": { "normal": { "model": "sbm:spruce_sign" } } } but I don't quite understand how to use IStateMapper . Could you explain in a little more detail?
  10. That seems to have done it, thanks! Now my only problem is that the particle effects from breaking the block are pink and black. Since the signs don't have a blockmodel I'm not sure how to change that. I actually noticed right now that the text on the sign doesn't save when i exit the world, the log says: [19:18:04] [server thread/ERROR] [FML]: A TileEntity type nu.aksberg.sbm.tileentity.TileEntitySpruceSign has throw an exception trying to write state. It will not persist. Report this to the mod author java.lang.RuntimeException: class nu.aksberg.sbm.tileentity.TileEntitySpruceSign is missing a mapping! This is a bug! What's that all about?
  11. That seems to have done it, thanks! Now my only problem is that the particle effects from breaking the block are pink and black. Since the signs don't have a blockmodel I'm not sure how to change that.
  12. Hi! I wanted to add a few custom signs to my mod so I looked a little at the default code and tried to create them as I normally do. public static void init() { public static Block spruce_standing_sign; public static Block spruce_wall_sign; } public static void register() { spruce_standing_sign = new BlockStandingSign().setUnlocalizedName("spruce_standing_sign"); spruce_wall_sign = new BlockWallSign().setUnlocalizedName("spruce_wall_sign"); } Since the BlockStandingSign and BlockWallSign were public and I didn't need to change anything in them I didn't create my own blockclasses for them. The only thing I changed was ItemSign were I overrode the "onItemUse" method so it would place my custom sign. @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (side == EnumFacing.DOWN) { return false; } else if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) { return false; } else { pos = pos.offset(side); if (!playerIn.canPlayerEdit(pos, side, stack)) { return false; } else if (!Blocks.standing_sign.canPlaceBlockAt(worldIn, pos)) { return false; } else if (worldIn.isRemote) { return true; } else { if (side == EnumFacing.UP) { int i = MathHelper.floor_double((double)((playerIn.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15; worldIn.setBlockState(pos, SBMBlocks.spruce_standing_sign.getDefaultState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3); } else { worldIn.setBlockState(pos, SBMBlocks.spruce_wall_sign.getDefaultState().withProperty(BlockWallSign.FACING, side), 3); } --stack.stackSize; TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack)) { playerIn.openEditSign((TileEntitySign)tileentity); } return true; } } } } This worked great on walls but when I tried to place a standing sign it had the right hitbox, was the right block according to F3 but it had no pole and wasn't rotated properly. Basically it was a floating wallsign. I cannot figure out what's wrong as I have not changed anything except the item which I have checked countless times. I'm a beginner though so it might just be some silly mistake I have missed. Oh and also, how would I go about adding a custom texture to it? Signs don't seem to have models.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.