• 0

    posted a message on Fix GUI Size for custom container

    It looks like the texture for the gui is squished. What does the gui texture look like?

    Posted in: Modification Development
  • 0

    posted a message on How to create a functional block like a crafting table

    Yes, the code I posted is for 1.12.2.


    For checking the source code, I know that if you use the standard "setupDecompWorkspace", then you should be able to check the source code under referenced libraries. It should be under something like forge-1.12.2, and then under net.minecraft.

    Posted in: Modification Development
  • 0

    posted a message on is it possible to make a mob with their arms beside their sides

    Sorry my wording was a bit misleading. I meant that it's not possible with just a resource pack.

    Posted in: Resource Pack Help
  • 0

    posted a message on Im haveing trouble with Render offsets for TOOLS and weapons.

    What version are you in?

    Posted in: Modification Development
  • 0

    posted a message on How to create a functional block like a crafting table

    I made something exactly like this once, so the code I am posting has a lot of references to the thing I did.

    So first, in your block class, you'll want to add this:

        public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
        {
            if (worldIn.isRemote)
            {
                return true;
            }
            else
            {
                playerIn.openGui(Main.instance, GuiIDs.METAL_WORKBENCH, worldIn, pos.getX(), pos.getY(), pos.getZ());
                return true;
            }
        }

    What this does is when the block is right clicked, it opens the gui (as long as the world is not remote, I forgot what exactly this means). In openGui, it wants the instance of your mod class, and the id, which it will send to your gui handler to get the correct things.


    As for the gui handler, you'll want to make a class like this:

    public class GuiHandler implements IGuiHandler{
    
    	@Override
    	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		IBlockState iblockstate = world.getBlockState(new BlockPos(x,y,z));
    		if(ID == GuiIDs.METAL_WORKBENCH && (iblockstate.getBlock() == RoHBlocks.METAL_WORKBENCH))
    			return new ContainerMetalWorkbench(player.inventory, world, new BlockPos(x, y, z));
            }
    
    	@Override
    	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		IBlockState iblockstate = world.getBlockState(new BlockPos(x,y,z));
    		if(ID == GuiIDs.METAL_WORKBENCH && (iblockstate.getBlock() == RoHBlocks.METAL_WORKBENCH))
    			return new GuiMetalWorkbench(player.inventory, world, new BlockPos(x, y, z));
            }
    }

    What this does is the server one gets called on the server and has to return the correct Container, while the client one has to return the correct GuiContainer. I just set it up so it checks that the id and the block match.


    The gui handler needs to be initialized and registered in the main mod class:

    private static GuiHandler guihandler = new GuiHandler();

    I don't remember why I registered it in the init phase.

    NetworkRegistry.INSTANCE.registerGuiHandler(instance, guihandler);

    Where instance is the instance of the mod class


    Here is the container class:


    public class ContainerMetalWorkbench extends Container{
        /** The crafting matrix inventory (3x3). */
        public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
        public InventoryCraftResult craftResult = new InventoryCraftResult();
        private final World world;
        /** Position of the workbench */
        private final BlockPos pos;
        private final EntityPlayer player;
    	
    	public ContainerMetalWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos blockPos) {
    		world = worldIn;
    		this.pos = blockPos;
    		this.player = playerInventory.player;
                    //This is the output slot
    		this.addSlotToContainer(new Workbench1SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));
    
            //These are the input slots
            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
                }
            }
            //these are the first 3 rows of inventory
            for (int k = 0; k < 3; ++k)
            {
                for (int i1 = 0; i1 < 9; ++i1)
                {
                    this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
                }
            }
            //this is the hotbar
            for (int l = 0; l < 9; ++l)
            {
                this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
            }
    	}
    
        /**
         * Callback for when the crafting matrix is changed.
         */
        public void onCraftMatrixChanged(IInventory inventoryIn)
        {
        		//craftResult.setInventorySlotContents(0, new ItemStack(Blocks.IRON_ORE));
            //craftResult.setInventorySlotContents(0, MetalWorkbenchCraftingHandler.instance().getResult(this.craftMatrix, world));
            if(!this.world.isRemote) {
            		EntityPlayerMP eplayer = (EntityPlayerMP) this.player;
                            //takes the items in the crafting matrix and finds a recipe with those things
            		IRecipe r = MetalWorkbenchCraftingHandler.instance().getResult((InventoryCrafting) inventoryIn, world);
            		ItemStack s;
            		if(r == null) s = ItemStack.EMPTY;
            		else{s = r.getCraftingResult(this.craftMatrix);}
            		this.craftResult.setInventorySlotContents(0, s);
            		eplayer.connection.sendPacket(new SPacketSetSlot(this.windowId, 0, s));
            }
        }
        
        
    
        /**
         * Called when the container is closed.
         */
        public void onContainerClosed(EntityPlayer playerIn)
        {
            super.onContainerClosed(playerIn);
    
            if (!this.world.isRemote)
            {
                this.clearContainer(playerIn, this.world, this.craftMatrix);
            }
        }
    
        /**
         * Determines whether supplied player can use this container
         */
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            if (this.world.getBlockState(this.pos).getBlock() != RoHBlocks.METAL_WORKBENCH)
            {
                return false;
            }
            else
            {
                return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
            }
        }
    
        /**
         * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
         * inventory and the other inventory(s).
         */
        public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
        {
            ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
    
            if (slot != null && slot.getHasStack())
            {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
    
                if (index == 0)
                {
                    itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);
    
                    if (!this.mergeItemStack(itemstack1, 10, 46, true))
                    {
                        return ItemStack.EMPTY;
                    }
    
                    slot.onSlotChange(itemstack1, itemstack);
                }
                else if (index >= 10 && index < 37)
                {
                    if (!this.mergeItemStack(itemstack1, 37, 46, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (index >= 37 && index < 46)
                {
                    if (!this.mergeItemStack(itemstack1, 10, 37, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (!this.mergeItemStack(itemstack1, 10, 46, false))
                {
                    return ItemStack.EMPTY;
                }
    
                if (itemstack1.isEmpty())
                {
                    slot.putStack(ItemStack.EMPTY);
                }
                else
                {
                    slot.onSlotChanged();
                }
    
                if (itemstack1.getCount() == itemstack.getCount())
                {
                    return ItemStack.EMPTY;
                }
    
                ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
    
                if (index == 0)
                {
                    playerIn.dropItem(itemstack2, false);
                }
            }
    
            return itemstack;
        }
    
        /**
         * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
         * is null for the initial slot that was double-clicked.
         */
        public boolean canMergeSlot(ItemStack stack, Slot slotIn)
        {
            return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
        }
    
    }


    So this class references a crafting handler, which I created to initialize the recipes and do some things like find the result of the recipes. I also used shaped recipes which technically doesn't need to be done, you just need a way to output the correct result


    The gui class:

    public class GuiMetalWorkbench extends GuiContainer{
    	private static final ResourceLocation METAL_WORKBENCH_GUI_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/gui/container/metal_workbench.png");
    	private final IInventory playerInventory;
        public GuiMetalWorkbench(InventoryPlayer inventory, World world, BlockPos blockPos) {
    		super(new ContainerMetalWorkbench(inventory, world, blockPos));
    		playerInventory=inventory;
    	}
    
    	/**
         * Draws the screen and all the components in it.
         */
        public void drawScreen(int mouseX, int mouseY, float partialTicks)
        {
            this.drawDefaultBackground();
            super.drawScreen(mouseX, mouseY, partialTicks);
            this.renderHoveredToolTip(mouseX, mouseY);
        }
        
        protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
        {
        		this.fontRenderer.drawString("Metal Workbench", 28, 6, 4210752);
            this.fontRenderer.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
        }
        
        protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
        {
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.getTextureManager().bindTexture(METAL_WORKBENCH_GUI_TEXTURE);
            int i = this.guiLeft;
            int j = (this.height - this.ySize) / 2;
            this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
        }
    
    }

    I mostly copied this from the crafting table gui I think.

    Posted in: Modification Development
  • 0

    posted a message on is it possible to make a mob with their arms beside their sides

    Do you mean like with a resource pack? If so, then no, because models are hard coded.

    Posted in: Resource Pack Help
  • 0

    posted a message on Smooth Stone does not use the "smooth_stone.png" in texture packs.

    What version are you using? This appears to be fixed in 1.16.

    Posted in: Resource Pack Help
  • 0

    posted a message on [Eclipse] Minecraft Crash

    There is a null pointer exception somewhere, I can't help you unless you post some of your code.

    Posted in: Modification Development
  • 0

    posted a message on creating dynamic textures and gui

    I don't know much about MCreator other than it seems like a nightmare to use, but I can tell you how to do this with forge. I would not be surprised to hear that MCreator is incapable of making a decent gui, this goes along with everything else I've heard about it. I'd recommend using forge since there are a lot of tutorials on it and you can do a lot with it. Making a dynamic textured gui is fairly easy with forge since the function to draw the gui gets called each frame.

    Posted in: Modification Development
  • 0

    posted a message on Trying to create a 1.12.2 Mod (from tutorial) | My item texture won't load

    It looks like the model isn't registered correctly in the code.

    Posted in: Modification Development
  • 0

    posted a message on How to create a functional block like a crafting table

    Sorry that this is a bit brief (I can give a longer explanation later), but here are the parts that you need:

    - A container class, which handles all of the server side stuff (like crafting)

    - A gui class (extending GuiContainer), which handles the client side stuff (like displaying the gui)

    - A gui handler, which ensures that the server and client get the right things, note that this needs to be registered using NetworkRegistry.INSTANCE.registerGuiHandler

    - In the block's class, you need to override onBlockActivated and open the gui

    Posted in: Modification Development
  • 0

    posted a message on trying to find an even that fires on after messing with a placed blocks inventory

    Try PlayerContainerEvent.Close for chests (and other containers), and PlayerInteractEvent.EntityInteractSpecific for armor stands and item frames.

    Posted in: Modification Development
  • 0

    posted a message on Crashing at forth stage of loading no errors in mod code.
    net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Crafters Dream (craftersdrm)
    Caused by: java.lang.NullPointerException
        at net.minecraftforge.registries.IForgeRegistryEntry$Impl.setRegistryName(IForgeRegistryEntry.java:79)
        at net.minecraftforge.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:203)
        at com.Proninja342.CraftersDream.CraftersDream.init(CraftersDream.java:54)

    There is some problem with the recipe.

    Posted in: Modification Development
  • 0

    posted a message on No Endermen in the End

    do /gamerule doMobSpawning false. It doesn't affect mob spawners.

    Posted in: Requests / Ideas For Mods
  • 1

    posted a message on Getting items present in chest

    Try using PlayerContainerEvent.Open. I suspect that GuiOpenEvent fires (on the client side, ofc) before a packet is sent with the information of what is contained in the chest to the client (from the wording in the javadoc, this appears to be the case).

    Posted in: Modification Development
  • To post a comment, please .