
Whyneb360
Members-
Posts
84 -
Joined
-
Last visited
Everything posted by Whyneb360
-
Thank you for your response, however I'm not sure where to put the the if statement you mentioned, or what the default value would be. Sorry if this seems like an obvious question
-
The crash report is as follows: [17:31:43] [Client thread/FATAL]: Reported exception thrown! net.minecraft.util.ReportedException: Rendering item at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:624) ~[RenderItem.class:?] at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) ~[GuiIngame.class:?] at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) ~[GuiIngameForge.class:?] at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) ~[GuiIngameForge.class:?] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114) ~[EntityRenderer.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1056) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?] at GradleStart.main(GradleStart.java:45) [start/:?] Caused by: java.lang.NullPointerException at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) ~[RenderPottedPlant.class:?] //int dir = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) ~[itemRenderPottedPlant.class:?] //this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F); at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) ~[ForgeHooksClient.class:?] at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) ~[RenderItem.class:?] ... 15 more [17:31:43] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ---- Time: 18/05/15 5:31 PM Description: Rendering item java.lang.NullPointerException: Rendering item at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1056) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) -- Item being rendered -- Details: Item Type: net.minecraft.item.ItemBlock@34d644b5 Item Aux: 0 Item NBT: null Item Foil: false Stacktrace: at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player37'/264, l='MpServer', x=59.02, y=70.62, z=232.56]] Chunk stats: MultiplayerChunkCache: 10, 10 Level seed: 0 Level generator: ID 00 - default, ver 1. Features enabled: false Level generator options: Level spawn location: World: (56,64,248), Chunk: (at 8,4,8 in 3,15; contains blocks 48,0,240 to 63,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 1321 game time, 1321 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 6 total; [EntityItem['item.item.seeds'/114, l='MpServer', x=32.81, y=63.13, z=212.25], EntitySquid['Squid'/115, l='MpServer', x=41.59, y=59.28, z=217.16], EntitySquid['Squid'/116, l='MpServer', x=47.94, y=55.34, z=209.31], EntityClientPlayerMP['Player37'/264, l='MpServer', x=59.02, y=70.62, z=232.56], EntitySquid['Squid'/125, l='MpServer', x=51.97, y=55.00, z=212.94], EntitySquid['Squid'/126, l='MpServer', x=52.84, y=54.00, z=209.50]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555) at net.minecraft.client.Minecraft.run(Minecraft.java:973) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) This... ...is where my code is first referenced in the crash log I believe Thanks, -Whyneb360 P.S. In the above crash report, I annotated which line of code related to the reference.
-
Hello all, I am having trouble rendering my custom modeled block - I wanted my block's model to face different directions depending on which way the player is facing, which works. The problem arises when I try and make and render my block as an item as well. Whenever I enter the game and the item is visible, the game crashes immediately. I believe I am doing it right, because when I remove the directional code, it renders fine with no crashes. How would I make these two functions work together? My code is as follows: Block Class public class PottedPlantProp extends BlockContainer { public PottedPlantProp(Material material) { super(material); this.setCreativeTab(DesconCreativeTabs.tabExterior); this.setHarvestLevel("", 1); this.setHardness(1F); this.setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.750F, 0.9375F); this.setBlockTextureName(Main.modID + ":" + "textures/blocks/pottedplant.png"); } public int getRenderType() { return -1; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityPottedPlant(); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5)); } //Directional Code /*public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, l, 3); }*/ } ClientProxy //Potted Plant TileEntitySpecialRenderer renderPottedPlant = new RenderPottedPlant(); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPottedPlant.class, renderPottedPlant); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(PropsGeneral.pottedplant), new ItemRenderPottedPlant(renderPottedPlant, new TileEntityPottedPlant())); ItemRenderer public class ItemRenderPottedPlant implements IItemRenderer { TileEntitySpecialRenderer render; private TileEntity entity; public ItemRenderPottedPlant(TileEntitySpecialRenderer render, TileEntity entity) { this.entity = entity; this.render = render; } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return true; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { if(type == IItemRenderer.ItemRenderType.ENTITY) GL11.glTranslatef(-0.5F, 0.0F, -0.5F); this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F); } } Block Renderer public class RenderPottedPlant extends TileEntitySpecialRenderer { private static final ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/props/PottedPlantTexture.png"); private ModelPottedPlant model; public RenderPottedPlant() { this.model = new ModelPottedPlant(); } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { /*World world = tileEntity.getWorldObj(); int dir = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); */ GL11.glPushMatrix(); GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glRotatef(180, 0F, 0F, 1F); //GL11.glRotatef(dir * (90F), 0F, 1F, 0F); this.bindTexture(texture); GL11.glPushMatrix(); this.model.renderModel(0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } } P.S. In the state the code is in above, the directional code has been commented out, so that the rendering works
-
[1.7.10] Making a 3x1x1 Block - Hit-box Problems
Whyneb360 replied to Whyneb360's topic in Modder Support
I hate to double post, but I'd still love some help with this -
[1.7.10] Making a 3x1x1 Block - Hit-box Problems
Whyneb360 replied to Whyneb360's topic in Modder Support
Sorry if this is an obvious question, but where and how would I set and use the metadata. Note that I am not just trying to texture the blocks differently, but I want one to have a model, and the others to not. I looked through the bed code, and found this: (warning, copy pasta ahead) @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { if (p_149691_1_ == 0) { return Blocks.planks.getBlockTextureFromSide(p_149691_1_); } else { int k = getDirection(p_149691_2_); int l = Direction.bedDirection[k][p_149691_1_]; int i1 = isBlockHeadOfBed(p_149691_2_) ? 1 : 0; return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1]; } } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_top"), p_149651_1_.registerIcon(this.getTextureName() + "_head_top")}; this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_end"), p_149651_1_.registerIcon(this.getTextureName() + "_head_end")}; this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_side"), p_149651_1_.registerIcon(this.getTextureName() + "_head_side")}; } Which is how the textures are set, but I'm not sure how I'd change this to set a model for one, and an invisible texture for another (Just in the case of 2 blocks) If needed, this is the code in my Workbench class, and my WorkbenchItem class (again, a bit of a copy pasta warning) Workbench: public class Workbench extends BlockContainer { public static final int[][] thing = new int[][] {{0, 1}, { -1, 0}, {0, -1}, {1, 0}}; @SideOnly(Side.CLIENT) private IIcon[] field_149980_b; @SideOnly(Side.CLIENT) private IIcon[] field_149982_M; @SideOnly(Side.CLIENT) private IIcon[] field_149983_N; public Workbench(Material material) { super(material); this.setCreativeTab(DesconCreativeTabs.tabInterior); this.setHarvestLevel("axe", 1); this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F); this.setHardness(3F); } public int getRenderType() { return -1; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityWorkbench(); } /*@SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5)); } */ //Directional Bollocks public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, l, 3); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) { if(!player.isSneaking()) { player.openGui(Main.instance, PropsGeneral.guiIDdesignersworkbench, world, x, y, z); return true; }else{ return false; } } public static boolean isBlockWorkbench(int isBlock) { return (isBlock & != 0; } public static int getDirection(int direction) { return direction & 3; } public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { int l = world.getBlockMetadata(x, y, z); int i1 = getDirection(l); if (isBlockWorkbench(l)) { if (world.getBlock(x - thing[i1][0], y, z - thing[i1][1]) != this) { world.setBlockToAir(x, y, z); } } else if (world.getBlock(x + thing[i1][0], y, z + thing[i1][1]) != this) { world.setBlockToAir(x, y, z); if (!world.isRemote) { this.dropBlockAsItem(world, x, y, z, l, 0); } } } public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return isBlockWorkbench(p_149650_1_) ? Item.getItemById(0) : DesconItems.workbench; } @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { if (p_149691_1_ == 0) { return Blocks.planks.getBlockTextureFromSide(p_149691_1_); } else { int k = getDirection(p_149691_2_); int l = Direction.bedDirection[k][p_149691_1_]; int i1 = isBlockWorkbench(p_149691_2_) ? 1 : 0; return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1]; } } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_top"), p_149651_1_.registerIcon(this.getTextureName() + "_head_top")}; this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_end"), p_149651_1_.registerIcon(this.getTextureName() + "_head_end")}; this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_side"), p_149651_1_.registerIcon(this.getTextureName() + "_head_side")}; } } WorkbenchItem: public class WorkbenchItem extends Item { private static final String __OBFID = "CL_00001771"; public WorkbenchItem() { } /** * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return * True if something happen and false if it don't. This is for ITEMS, not BLOCKS */ public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int i, float x1, float y1, float z1) { if (world.isRemote) { return true; } else if (i != 1) { return false; } else { ++y; Workbench workbench = (Workbench)PropsGeneral.designersworkbench; int i1 = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; byte b0 = 0; byte b1 = 0; if (i1 == 0) { b1 = 1; } if (i1 == 1) { b0 = -1; } if (i1 == 2) { b1 = -1; } if (i1 == 3) { b0 = 1; } if (player.canPlayerEdit(x, y, z, i, itemstack) && player.canPlayerEdit(x + b0, y, z + b1, i, itemstack)) { if (world.isAirBlock(x, y, z) && world.isAirBlock(x + b0, y, z + b1) && World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && World.doesBlockHaveSolidTopSurface(world, x + b0, y - 1, z + b1)) { world.setBlock(x, y, z, workbench, i1, 3); if (world.getBlock(x, y, z) == workbench) { world.setBlock(x + b0, y, z + b1, workbench, i1 + 8, 3); } --itemstack.stackSize; return true; } else { return false; } } else { return false; } } } } -Whyneb360 -
[1.7.10] Making a 3x1x1 Block - Hit-box Problems
Whyneb360 replied to Whyneb360's topic in Modder Support
Okay, so my block spawns in with the second one attached (and gets destroyed as well), but how do I make it two different blocks? At the moment its the same block that spawns in, so I think it might have something to do with metadata in the case of the bed, so do I have to set up some metadata? All I want is for the model to only spawn on the first block, not the second -Whyneb360 -
[1.7.10] Making a 3x1x1 Block - Hit-box Problems
Whyneb360 replied to Whyneb360's topic in Modder Support
Could you please explain this in a bit more detail? I am somewhat new to modding, but very new to the more complicated aspects of block placement (which this query seems to be). I looked through the bed and door code, but I couldn't find anything that uses the 'onBlockPlacedinWorld' method -Whyneb360 -
So I have a modeled block that is, as said above, 3x1x1 (3 blocks wide, 1 block high, and 1 block in depth) and it looks fine, but the hit-box only works for the center block. Through a bit of research I found out that I need to create two other blocks that 'spawn in' on either side when I place the main block, but I'm not sure how to go about this. Any help would be greatly appreciated, -Whyneb360
-
I am trying to make a 2x1x1 Block, and have managed that, but the block bounds don't work for it. When looking a the left half of the block, you can interact with it and break it and even see that the bounds are 2x1x1, but when I move my mouse over to the right side of the block the hitbox disappears and I can even place a block in the right half. Any idea on how to fix this? -Whyneb360 P.S. I know I'll need to rotate the hitbox, and that parts all settled. Just trying to figure out how to make a functional 2x1x1 hitbox first this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 2.0F);
-
That was it! Thank you very much -Whyneb360
-
Okay, so I can see what you're doing wrong, but I'm not confident in my ability to explain it - bear with me. I hate to post code, but I hope that in making it not 'copy-pastable', you will still need to learn and understand it. Where you have your first method and resource location, try using this: private static final ResourceLocation textureLocation = new ResourceLocation([mainclass.modid + ":" + "textures/entity/yourtexture.png"); and then where you've said this.bindtexture... down the bottom, get ride of the object (this.). I think the problem you're having is that you might have been using an outdated thread? Anyway. See if this works. If it doesn't then restart following this: (Part 1 - Model itself) and (Part 2 - Coding it in) P.S. Make sure the resource location variable is the same as your bind texture variable and that your texture file is inside the textures/entity path - entity being a folder.
-
I have made a breakthrough. When I tested the crafting originally, I just put the recipe into the custom crafting table and since no icon appeared in the output slot, I assumed it didn't work. Just now I tried clicking that empty slot, and the materials disappeared and I got the item(successful crafting procedure). Then I tried a vanilla crafting recipe (wooden button for example) and even though that output icon (of the wooden button) does appear in the output slot, I can't craft it/take it out of the output slot. So my new problem is making the icon for my custom recipes appear, and the icon for the old recipes disappear. Tell me if I need to clarify anything
-
Here you go: GUIHandler public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case PropsGeneral.guiIDdesignersworkbench: if (entity instanceof TileEntityWorkbench) { return new ContainerWorkbench(player.inventory, (TileEntityWorkbench) entity, world, x, y, z); } return null; } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case PropsGeneral.guiIDdesignersworkbench: if (entity instanceof TileEntityWorkbench) { return new GuiWorkbench(player.inventory, world, x, z, z); } } } return null; } } GUIWorkbench public class GuiWorkbench extends GuiContainer{ private ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/gui/WorkbenchTexture.png"); public GuiWorkbench(InventoryPlayer invPlayer, World world, int x, int y, int z) { super(new ContainerWorkbench(invPlayer, world, x, y, z)); // TODO Auto-generated constructor stub this.xSize = 176; this.ySize = 166; } public void onGuiClosed() { super.onGuiClosed(); } protected void drawGuiContainerForegroundLayer(int i, int j) { this.fontRendererObj.drawString(StatCollector.translateToLocal("Designer's Workbench"), 20, 10, 0xFFFFFF); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { GL11.glColor4f(1F, 1F, 1F, 1F); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } }
-
Sure thing: ContainerWorkbench class (Where the onCraftMatricChanged method is) public class ContainerWorkbench extends Container { public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); public IInventory craftResult = new InventoryCraftResult(); private World worldObj; private int posX; private int posY; private int posZ; private static final String __OBFID = "CL_00001744"; public ContainerWorkbench(InventoryPlayer invplayer, TileEntityWorkbench entity, World world, int x, int y, int z) { this.worldObj = world; this.posX = x; this.posY = y; this.posZ = z; this.addSlotToContainer(new SlotCrafting(invplayer.player, this.craftMatrix, this.craftResult, 0, 124, 35)); int l; int i1; for (l = 0; l < 3; ++l) { for (i1 = 0; i1 < 3; ++i1) { this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18)); } } for (l = 0; l < 3; ++l) { for (i1 = 0; i1 < 9; ++i1) { this.addSlotToContainer(new Slot(invplayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18)); } } for (l = 0; l < 9; ++l) { this.addSlotToContainer(new Slot(invplayer, l, 8 + l * 18, 142)); } this.onCraftMatrixChanged(this.craftMatrix); } public void onCraftMatrixChanged(IInventory inventory) { this.craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } public boolean canInteractWith(EntityPlayer player) { return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != PropsGeneral.designersworkbench ? false : player.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D; } public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); if (!this.worldObj.isRemote) { for (int i = 0; i < 9; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { player.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public ItemStack transferStackInSlot(EntityPlayer entityplayer, int q) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(q); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (q == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (q >= 10 && q < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (q >= 37 && q < 46) { if (!this.mergeItemStack(itemstack1, 10, 37, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 10, 46, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(entityplayer, itemstack1); } return itemstack; } } WorkBenchShapedRecipes and its shapless counterpart is directly from the vanilla code Workbench class public class Workbench extends BlockContainer { public Workbench(Material material) { super(material); this.setCreativeTab(DesconCreativeTabs.tabGeneral); this.setHarvestLevel("axe", 1); this.setHardness(3F); this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 2F); } public int getRenderType() { return -1; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityWorkbench(); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5)); } //Directional Bollocks public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, l, 3); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) { if(!player.isSneaking()) { player.openGui(Main.instance, PropsGeneral.guiIDdesignersworkbench, world, x, y, z); return true; }else{ return false; } } }
-
Exactly. In my custom crafting manager, all the normal crafting recipes shouldn't work, and the ones I've put in should. In reality, it's the other way around - all the normal ones work (vanilla recipes that is), but the ones I've put in don't.
-
Sorry to bump up the topic, but I'd still love to get this working. Thanks, -Whyneb360
-
I added the breakpoint, but the game never gets to it. Do I need to initialize something in my main class?
-
So learning from my previous post, I won't be posting a metric ton of code, but I still need help. I managed to solve the problem of inventory moving, but I don't think I've activated my crafting manager properly. Crafting works fine in the custom crafting table, but it's just the normal recipes (which shouldn't work) and none of the ones in my custom crafting manager work either. Here is where I referenced it: public void onCraftMatrixChanged(IInventory inventory) { this.craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } In my container class. and this is my crafting manager (Copy pasta warning) public class WorkBenchCraftingManager { /** The static instance of this class */ private static final WorkBenchCraftingManager instance = new WorkBenchCraftingManager(); /** A list of all the recipes added */ private List recipes = new ArrayList(); private static final String __OBFID = "CL_00000090"; /** * Returns the static instance of this class */ public static final WorkBenchCraftingManager getInstance() { /** The static instance of this class */ return instance; } private WorkBenchCraftingManager() { recipes = new ArrayList(); this.addRecipe(new ItemStack(PropsModern.laptop, 1), new Object[] {"S", "S", "S", 'S', Items.stick}); Collections.sort(this.recipes, new WorkBenchRecipeSorter(this)); } public WorkBenchShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) { String s = ""; int i = 0; int j = 0; int k = 0; if (par2ArrayOfObj[i] instanceof String[]) { String[] astring = (String[])((String[])par2ArrayOfObj[i++]); for (int l = 0; l < astring.length; ++l) { String s1 = astring[l]; ++k; j = s1.length(); s = s + s1; } }else{ while (par2ArrayOfObj[i] instanceof String) { String s2 = (String)par2ArrayOfObj[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2) { Character character = (Character)par2ArrayOfObj[i]; ItemStack itemstack1 = null; if (par2ArrayOfObj[i + 1] instanceof Item) { itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]); } else if (par2ArrayOfObj[i + 1] instanceof Block) { itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767); } else if (par2ArrayOfObj[i + 1] instanceof ItemStack) { itemstack1 = (ItemStack)par2ArrayOfObj[i + 1]; } hashmap.put(character, itemstack1); } ItemStack[] aitemstack = new ItemStack[j * k]; for (int i1 = 0; i1 < j * k; ++i1) { char c0 = s.charAt(i1); if (hashmap.containsKey(Character.valueOf(c0))) { aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy(); } else { aitemstack[i1] = null; } } WorkBenchShapedRecipes shapedrecipes = new WorkBenchShapedRecipes(j, k, aitemstack, par1ItemStack); this.recipes.add(shapedrecipes); return shapedrecipes; } public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) { ArrayList arraylist = new ArrayList(); Object[] aobject = par2ArrayOfObj; int i = par2ArrayOfObj.length; for (int j = 0; j < i; ++j) { Object object1 = aobject[j]; if (object1 instanceof ItemStack) { arraylist.add(((ItemStack)object1).copy()); } else if (object1 instanceof Item) { arraylist.add(new ItemStack((Item)object1)); } else { if (!(object1 instanceof Block)) { throw new RuntimeException("Invalid shapeless recipe!"); } arraylist.add(new ItemStack((Block)object1)); } } this.recipes.add(new ShapelessRecipes(par1ItemStack, arraylist)); } public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World) { int i = 0; ItemStack itemstack = null; ItemStack itemstack1 = null; int j; for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j) { ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j); if (itemstack2 != null) { if (i == 0) { itemstack = itemstack2; } if (i == 1) { itemstack1 = itemstack2; } ++i; } } if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) { Item item = itemstack.getItem(); int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay(); int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); int l = j1 + k + item.getMaxDamage() * 5 / 100; int i1 = item.getMaxDamage() - l; if (i1 < 0) { i1 = 0; } return new ItemStack(itemstack.getItem(), 1, i1); } else { for (j = 0; j < this.recipes.size(); ++j) { IRecipe irecipe = (IRecipe)this.recipes.get(j); if (irecipe.matches(par1InventoryCrafting, par2World)) { return irecipe.getCraftingResult(par1InventoryCrafting); } } return null; } } /** * returns the List<> of all recipes */ public List getRecipeList() { return this.recipes; } } Which is almost straight from the vanilla code Thanks in advance, -Whyneb360
-
Thanks, now I know for next time, but it seems like all of my issues are related to the inventory being messed up. It makes sense that the crafting would be off if all the the inventory slots are messed up. Going from the original crafting table to my own, the inventory switches around and goes all out of order and duplicated. Sorry about my previous post, but whereabouts would this code be? Thanks, -Whyneb360
-
So, as the title says, I am making a custom crafting table. My issues are as follows: 1. Shift clicking a stack of items crashes the game 2. When you open the crafting table, your inventory moves all over the place, and sometimes items duplicate or move to the crafting grid by themselves 3. Custom crafting recipes don't work Here is the code for all my related classes (Sorry about the copy pasta): ContainerWorkbench: package com.descon.container; import com.descon.mod.WorkBenchCraftingManager; import com.descon.propsmain.PropsGeneral; import com.descon.tileentity.TileEntityWorkbench; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ContainerWorkbench extends Container { public InventoryCrafting craftMatrix; public IInventory craftResult; private World worldObj; private int posX; private int posY; private int posZ; public ContainerWorkbench (InventoryPlayer inventory, TileEntityWorkbench entity, World world, int x, int y, int z) { craftMatrix = new InventoryCrafting(this, 3, 3); craftResult = new InventoryCraftResult(); worldObj = world; posX = x; posY = y; posZ = z; int l; int i1; for (l = 0; l < 3; ++l) { for (i1 = 0; i1 < 3; ++i1) { this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18)); } } for (l = 0; l < 3; ++l) { for (i1 = 0; i1 < 9; ++i1) { this.addSlotToContainer(new Slot(inventory, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18)); } } for (l = 0; l < 9; ++l) { this.addSlotToContainer(new Slot(inventory, l, 8 + l * 18, 142)); } this.onCraftMatrixChanged(this.craftMatrix); } public void onCraftMatricChanged(IInventory iiventory) { craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj)); } @Override public boolean canInteractWith(EntityPlayer player) { if(worldObj.getBlock(posX, posY, posZ) != PropsGeneral.designersworkbench) { return false; }else{ return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D; } } public void onContainerClosed(EntityPlayer p_75134_1_) { super.onContainerClosed(p_75134_1_); if (!this.worldObj.isRemote) { for (int i = 0; i < 9; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public ItemStack transferStackInSlot(EntityPlayer entityplayer, int q) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(q); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (q == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (q >= 10 && q < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (q >= 37 && q < 46) { if (!this.mergeItemStack(itemstack1, 10, 37, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 10, 46, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(entityplayer, itemstack1); } return itemstack; } } GuiHandler: package com.descon.gui; import com.descon.container.ContainerWorkbench; import com.descon.propsmain.PropsGeneral; import com.descon.tileentity.TileEntityWorkbench; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case PropsGeneral.guiIDdesignersworkbench: if (entity instanceof TileEntityWorkbench) { return new ContainerWorkbench(player.inventory, (TileEntityWorkbench) entity, world, x, y, z); } return null; } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case PropsGeneral.guiIDdesignersworkbench: if (entity instanceof TileEntityWorkbench) { return new GuiWorkbench(player.inventory, world, x, z, z); } } } return null; } } GuiWorkbench: package com.descon.gui; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import com.descon.mod.Main; public class GuiWorkbench extends GuiContainer{ private ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/gui/WorkbenchTexture.png"); public GuiWorkbench(InventoryPlayer invPlayer, World world, int x, int y, int z) { super(new ContainerWorkbench(invPlayer, world, x, y, z)); // TODO Auto-generated constructor stub this.xSize = 176; this.ySize = 166; } public void onGuiClosed() { super.onGuiClosed(); } protected void drawGuiContainerForegroundLayer(int i, int j) { this.fontRendererObj.drawString(StatCollector.translateToLocal("Designer's Workbench"), 100, 5, 0x000000); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { GL11.glColor4f(1F, 1F, 1F, 1F); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } } Main class FMLInitializationEvent: @EventHandler public void init(FMLInitializationEvent preEvent) { //Renderers desconProxy.registerRenderThing(); desconProxy.registerItemRenderers(); NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); WorkBenchCraftingManager: package com.descon.mod; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import com.descon.crafting.WorkBenchShapedRecipes; import com.descon.propsmain.PropsModern; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.RecipeBookCloning; import net.minecraft.item.crafting.RecipeFireworks; import net.minecraft.item.crafting.RecipesArmor; import net.minecraft.item.crafting.RecipesArmorDyes; import net.minecraft.item.crafting.RecipesCrafting; import net.minecraft.item.crafting.RecipesDyes; import net.minecraft.item.crafting.RecipesFood; import net.minecraft.item.crafting.RecipesIngots; import net.minecraft.item.crafting.RecipesMapCloning; import net.minecraft.item.crafting.RecipesMapExtending; import net.minecraft.item.crafting.RecipesTools; import net.minecraft.item.crafting.RecipesWeapons; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.world.World; public class WorkBenchCraftingManager { /** The static instance of this class */ private static final WorkBenchCraftingManager instance = new WorkBenchCraftingManager(); /** A list of all the recipes added */ private List recipes = new ArrayList(); private static final String __OBFID = "CL_00000090"; /** * Returns the static instance of this class */ public static final WorkBenchCraftingManager getInstance() { /** The static instance of this class */ return instance; } private WorkBenchCraftingManager() { recipes = new ArrayList(); this.addRecipe(new ItemStack(PropsModern.laptop, 1), new Object[] {"SSS", "SSS", "SSS", 'S', Items.stick}); Collections.sort(this.recipes, new WorkBenchRecipeSorter(this)); } public WorkBenchShapedRecipes addRecipe(ItemStack p_92103_1_, Object ... p_92103_2_) { String s = ""; int i = 0; int j = 0; int k = 0; if (p_92103_2_[i] instanceof String[]) { String[] astring = (String[])((String[])p_92103_2_[i++]); for (int l = 0; l < astring.length; ++l) { String s1 = astring[l]; ++k; j = s1.length(); s = s + s1; } } else { while (p_92103_2_[i] instanceof String) { String s2 = (String)p_92103_2_[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = new HashMap(); i < p_92103_2_.length; i += 2) { Character character = (Character)p_92103_2_[i]; ItemStack itemstack1 = null; if (p_92103_2_[i + 1] instanceof Item) { itemstack1 = new ItemStack((Item)p_92103_2_[i + 1]); } else if (p_92103_2_[i + 1] instanceof Block) { itemstack1 = new ItemStack((Block)p_92103_2_[i + 1], 1, 32767); } else if (p_92103_2_[i + 1] instanceof ItemStack) { itemstack1 = (ItemStack)p_92103_2_[i + 1]; } hashmap.put(character, itemstack1); } ItemStack[] aitemstack = new ItemStack[j * k]; for (int i1 = 0; i1 < j * k; ++i1) { char c0 = s.charAt(i1); if (hashmap.containsKey(Character.valueOf(c0))) { aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy(); } else { aitemstack[i1] = null; } } WorkBenchShapedRecipes shapedrecipes = new WorkBenchShapedRecipes(j, k, aitemstack, p_92103_1_); this.recipes.add(shapedrecipes); return shapedrecipes; } public void addShapelessRecipe(ItemStack p_77596_1_, Object ... p_77596_2_) { ArrayList arraylist = new ArrayList(); Object[] aobject = p_77596_2_; int i = p_77596_2_.length; for (int j = 0; j < i; ++j) { Object object1 = aobject[j]; if (object1 instanceof ItemStack) { arraylist.add(((ItemStack)object1).copy()); } else if (object1 instanceof Item) { arraylist.add(new ItemStack((Item)object1)); } else { if (!(object1 instanceof Block)) { throw new RuntimeException("Invalid shapeless recipe!"); } arraylist.add(new ItemStack((Block)object1)); } } this.recipes.add(new ShapelessRecipes(p_77596_1_, arraylist)); } public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_) { int i = 0; ItemStack itemstack = null; ItemStack itemstack1 = null; int j; for (j = 0; j < p_82787_1_.getSizeInventory(); ++j) { ItemStack itemstack2 = p_82787_1_.getStackInSlot(j); if (itemstack2 != null) { if (i == 0) { itemstack = itemstack2; } if (i == 1) { itemstack1 = itemstack2; } ++i; } } if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) { Item item = itemstack.getItem(); int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay(); int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); int l = j1 + k + item.getMaxDamage() * 5 / 100; int i1 = item.getMaxDamage() - l; if (i1 < 0) { i1 = 0; } return new ItemStack(itemstack.getItem(), 1, i1); } else { for (j = 0; j < this.recipes.size(); ++j) { IRecipe irecipe = (IRecipe)this.recipes.get(j); if (irecipe.matches(p_82787_1_, p_82787_2_)) { return irecipe.getCraftingResult(p_82787_1_); } } return null; } } /** * returns the List<> of all recipes */ public List getRecipeList() { return this.recipes; } } WorkBenchRecipeSorter: package com.descon.mod; import java.util.Comparator; import com.descon.crafting.WorkBenchShapedRecipes; import com.descon.crafting.WorkBenchShapelessRecipes; import net.minecraft.item.crafting.IRecipe; public class WorkBenchRecipeSorter implements Comparator { final WorkBenchCraftingManager workSurface; public WorkBenchRecipeSorter(WorkBenchCraftingManager workbenchcraftingmanager) { this.workSurface = workbenchcraftingmanager; } public int compareRecipes(IRecipe irecipe1, IRecipe irecipe2) { return irecipe1 instanceof WorkBenchShapelessRecipes && irecipe2 instanceof WorkBenchShapedRecipes ? 1: (irecipe2 instanceof WorkBenchShapelessRecipes && irecipe1 instanceof WorkBenchShapedRecipes ? -1 :(irecipe2.getRecipeSize() < irecipe1.getRecipeSize() ? -1 : (irecipe2.getRecipeSize() > irecipe1.getRecipeSize() ? 1 : 0))); } @Override public int compare(Object o1, Object o2) { return this.compareRecipes((IRecipe)o1, (IRecipe)o2); } } Workbench Block Class: package com.descon.propsmain; import com.descon.mod.DesconCreativeTabs; import com.descon.mod.Main; import com.descon.tileentity.TileEntityPlasmaTubeLight; import com.descon.tileentity.TileEntityWorkbench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class Workbench extends BlockContainer { public Workbench(Material material) { super(material); this.setCreativeTab(DesconCreativeTabs.tabGeneral); this.setHarvestLevel("axe", 1); this.setHardness(3F); this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 2F); } public int getRenderType() { return -1; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityWorkbench(); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5)); } //Directional Bollocks public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, l, 3); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) { if(!player.isSneaking()) { player.openGui(Main.instance, PropsGeneral.guiIDdesignersworkbench, world, x, y, z); return true; }else{ return false; } } } I think that's it. Any help would be greatly appreciated -Whyneb360
-
So my problem is that I made a model in Techne, and scaled it down to 0.7 on the x, y, and z. I've put many other models into the game, and they work perfectly, but when I tried to use GL11.glscalef(0.7F, 0.7F, 0.7F) it scaled the model down, but completely messed up the way you see it in the world. It's a bit hard to explain, but it was no longer a static block that you placed and it stayed there. It could be seen through blocks, and as you walk around it it moves all over the place. As you walk, it has the same weird bobbing effect. This is my code for the render class: public class RenderLaptop extends TileEntitySpecialRenderer { private static final ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/props/LaptopTexture.png"); private ModelLaptop model; public RenderLaptop() { this.model = new ModelLaptop(); } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { World world = tileEntity.getWorldObj(); int dir = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); GL11.glPushMatrix(); GL11.glScafef(0.7F, 0.7F, 0.7F); GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glRotatef(180, 0F, 0F, 1F); GL11.glRotatef(dir * (90F), 0F, 1F, 0F); this.bindTexture(texture); this.model.renderModel(0.0625F); GL11.glPopMatrix(); } } Any help would be greatly appreciated
-
[1.7.10][SOLVED]Custom Rendered Block rotation and with hitbox
Whyneb360 replied to Wyverndoes's topic in Modder Support
I made a fairly huge topic that should help you to find an answer - the post is called '[1.7.10] Directional Models' and should just be about 10 or so topics below this one -
So as in my previous post, I needed to rotate the model, which I have done successfully.There are a few things that need fixing though. 1. How do I make the hitbox rotate with the model? and 2. How do I make my model render as the model in my inventory? Hitbox stuff: this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F); ClientProxy: public void registerRenderThing() { //Campfire TileEntitySpecialRenderer renderCampfire = new RenderCampfire(); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCampFire.class, renderCampfire); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(PropsGeneral.campfire), new ItemRendererCampfire(renderCampfire, new TileEntityCampFire())); } ItemRenderer: public class ItemRendererCampfire implements IItemRenderer { TileEntitySpecialRenderer render; private TileEntity entity; public ItemRendererCampfire(TileEntitySpecialRenderer render, TileEntity entity) { this.entity = entity; this.render = render; } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return true; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { if (type == IItemRenderer.ItemRenderType.ENTITY) GL11.glTranslatef(-0.5F, -0.0F, -0.5F); this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F); } }
-
Thank you very much, I managed to get to a point where the model is rotating, I just need to tweak a few numbers. There is only one thing I don't know how to fix. How do I rotate the model's hitbox as well?
-
I apolologise in advance, but as I am new to forge, I am not quite sure where to put the tileEntity.xCoord, .yCoord and .zCoord. I tried replacing the double x, y and z, but it didn't work, and I didn't think that would be right. If it was for World world = tileEntrity.xCoord, it throws and error when written like that. Sorry if I am missing something obvious, but I am eager to learn how to do this. EDIT: Okay, got it to work, so thanks. Do you have any suggestions for making the hitbox rotate as well? this.setBlockBounds(0F, 0F, 1F, 1F, 1F, 0.875F); is what I have at the moment