Jump to content

[1.7.2]Gui not opening, searched helps, nothing found.


lorizz

Recommended Posts

Hi guys, it's me, lorizz.

Yesterday I started creating a mod for the 1.7.2 version and I'm at the point to make a custom Crafting Table, I know how to do it but the problem is.

 

I followed a 1.6.4 tutorial on making a Gui/Container with the GuiHandler class and updated all functions/method to 1.7.2, no errors were found.

 

But the problem is that everytime I try to right click on my custom block, the gui doesn't show, no crash, nothing happens.

I searched a lot on this forum and someone found a way to fix it without explaining how.

Those are all my classes:

 

Main class:

 

package it.edennetwork.alum.main;

import it.edennetwork.alum.handlers.GuiHandler;
import it.edennetwork.alum.player.PlayerEventHandler;
import it.edennetwork.alum.registries.RegBlock;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;

@Mod(modid = AncientLumendell.modid, name = "Ancient Lumendell", version = "Alpha 1.0")
public class AncientLumendell {

public static final String modid = "gm_alum_alpha";

@Instance(value = AncientLumendell.modid)
public static AncientLumendell instance;

@SidedProxy(clientSide = "it.edennetwork.alum.main.ClientProxy", serverSide = "it.edennetwork.alum.main.ServerProxy")
public static ServerProxy proxy;

@EventHandler
public void onPreLoad(FMLPreInitializationEvent e) {

}

@EventHandler
public void onLoad(FMLInitializationEvent e) {
	proxy.initRenderers();
	proxy.initSounds();

	NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

	RegBlock.init();
	RegBlock.registerBlocks();
	RegBlock.addNames();

	MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
}

@EventHandler
public void onPostLoad(FMLPostInitializationEvent e) {

}
}

 

 

Gui Handler:

 

package it.edennetwork.alum.handlers;

import it.edennetwork.alum.containers.ContainerFoundry;
import it.edennetwork.alum.guis.GuiFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;

public class GuiHandler implements IGuiHandler {

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 GuiFoundry.id:
			if (entity instanceof TileEntityFoundry) {
				return new ContainerFoundry(player.inventory,
						(TileEntityFoundry) entity);
			}
		}
	}

	return null;
}

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 GuiFoundry.id:
			if (entity instanceof TileEntityFoundry) {
				return new GuiFoundry(player.inventory,
						(TileEntityFoundry) entity);
			}
		}
	}

	return null;
}
}

 

 

GuiFoundry:

 

package it.edennetwork.alum.guis;

import it.edennetwork.alum.containers.ContainerFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

public class GuiFoundry extends GuiContainer {

public static final int id = 0;

public static final ResourceLocation guiTexture = new ResourceLocation(
		AncientLumendell.modid, "textures/guis/gui_foundry.png");

public TileEntityFoundry foundry;

public GuiFoundry(InventoryPlayer invPlayer,
		TileEntityFoundry entity) {
	super(new ContainerFoundry(invPlayer, entity));

	this.foundry = entity;

	xSize = 344;
	ySize = 310;
}

@Override
public void drawGuiContainerBackgroundLayer(float f, int j, int i) {
	GL11.glColor4f(1F, 1F, 1F, 1F);
	Minecraft.getMinecraft().renderEngine.bindTexture(guiTexture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
}

 

 

ContainerFoundry:

 

package it.edennetwork.alum.containers;

import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;

public class ContainerFoundry extends Container {

private TileEntityFoundry foundry;

public ContainerFoundry(InventoryPlayer invPlayer, TileEntityFoundry entity) {
	this.foundry = entity;
}

@Override
public boolean canInteractWith(EntityPlayer player) {
	return foundry.isUseableByPlayer(player);
}
}

 

 

TileEntityFoundry:

 

package it.edennetwork.alum.tileentities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityFoundry extends TileEntity implements IInventory {

private ItemStack[] inventory;

public TileEntityFoundry() {
	inventory = new ItemStack[1];
}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return inventory[i];
}

@Override
public ItemStack decrStackSize(int slot, int count) {
	ItemStack itemstack = getStackInSlot(slot);

	if (itemstack != null) {
		if (itemstack.stackSize <= count) {
			setInventorySlotContents(slot, null);
		} else {
			itemstack = itemstack.splitStack(count);
			updateEntity();
		}
	}
	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack itemstack = getStackInSlot(slot);
	setInventorySlotContents(slot, null);
	return itemstack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
	inventory[slot] = itemstack;

	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
		itemstack.stackSize = getInventoryStackLimit();
	}
	updateEntity();
}

@Override
public String getInventoryName() {
	return "Fonderia";
}

@Override
public boolean hasCustomInventoryName() {
	return true;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord,
			this.zCoord) != this ? false : player.getDistanceSq(
			(double) this.xCoord + 0.5D, (double) this.yCoord + 0.5F,
			(double) this.zCoord + 0.5D) <= 64.0D;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
	return true;
}

@Override
public void readFromNBT(NBTTagCompound p_145839_1_) {
	super.readFromNBT(p_145839_1_);
}

@Override
public void writeToNBT(NBTTagCompound p_145841_1_) {
                super.writeToNBT(p_145841_1_);
}
}

 

 

BlockFoundry:

 

package it.edennetwork.alum.blocks;

import it.edennetwork.alum.guis.GuiFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
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.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockFoundry extends Block {

public BlockFoundry(Material material) {
	super(material);
	this.setBlockName("block_foundry");
	this.setCreativeTab(CreativeTabs.tabDecorations);
	this.setHardness(5F);
	this.setResistance(10F);
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z,
		EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
	if (!world.isRemote) {
		FMLNetworkHandler.openGui(player, AncientLumendell.instance,
				GuiFoundry.id, world, x, y, z);
	}
	return true;
}

@SideOnly(Side.CLIENT)
public static IIcon topIcon;
@SideOnly(Side.CLIENT)
public static IIcon frontIcon;
@SideOnly(Side.CLIENT)
public static IIcon sideIcon;

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
	topIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_top");
	frontIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_front");
	sideIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_side");
}

@Override
public IIcon getIcon(int side, int meta) {
	if (side == 0 || side == 1) {
		return topIcon;
	} else if (side == 2) {
		return frontIcon;
	} else {
		return sideIcon;
	}
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	super.onBlockAdded(world, x, y, z);
	this.setDefaultDirection(world, x, y, z);
}

private void setDefaultDirection(World world, int x, int y, int z) {
	if (!world.isRemote) {
		Block block = world.getBlock(x, y, z - 1);
		Block block1 = world.getBlock(x, y, z + 1);
		Block block2 = world.getBlock(x - 1, y, z);
		Block block3 = world.getBlock(x + 1, y, z);
		byte b0 = 3;

		if (block.func_149730_j() && !block1.func_149730_j()) {
			b0 = 3;
		}

		if (block1.func_149730_j() && !block.func_149730_j()) {
			b0 = 2;
		}

		if (block2.func_149730_j() && !block3.func_149730_j()) {
			b0 = 5;
		}

		if (block3.func_149730_j() && !block2.func_149730_j()) {
			b0 = 4;
		}

		world.setBlockMetadataWithNotify(x, y, z, b0, 2);
	}
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
		EntityLivingBase entity, ItemStack itemstack) {
	int rotation = MathHelper
			.floor_double((double) (entity.rotationYaw * 4F / 360F) + 0.5D) & 3;

	if (rotation == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}

	if (rotation == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}

	if (rotation == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}

	if (rotation == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}
}

@Override
public TileEntity createTileEntity(World var1, int var2) {
	// TODO Auto-generated method stub
	return new TileEntityFoundry();
}

@Override
public boolean hasTileEntity() {
	return true;
}
}

 

 

And finally the method I use to register the TileEntity:

public void initRenderers() {
GameRegistry.registerTileEntity(TileEntityFoundry.class, "alum_te_foundry");
}

 

Why the gui is not working? Thanks!

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Heres a updated version of my github https://github.com/THEKINGSKULL01/TSOTD0.0.30Forge1.20.1
    • When i go to the forge website to download any of the choices of versions I am unable to download anything. It just says that I am unable to reach this website for some reason.
    • hi everyone how can i make this script smoother or make them delay    @SubscribeEvent(       priority = EventPriority.HIGH    )    public void renderCrosshair(RenderGameOverlayEvent event) {       if(mc.gameSettings.guiScale == 2) {       Minecraft minecraft = Minecraft.getMinecraft();       if(event.type == ElementType.CROSSHAIRS && isGunInHand(minecraft.thePlayer)) {          event.setCanceled(true);          Icon crosshairIcon = ClientProxy.iconRegistry.crosshairIcon;          double scale = 6.0F + getScaleByMotion(minecraft.thePlayer);          if(FlansModClient.currentScope == null)          scale = 45.0F + getScaleByMotion(minecraft.thePlayer);                    GL11.glPushAttrib(16384);          GL11.glPushMatrix();          GL11.glEnable(3042);          OpenGlHelper.glBlendFunc(775, 769, 1, 0);          GL11.glEnable(3008);          GL11.glColor3d(1.0D, 1.0D, 1.0D);          GL11.glTranslated((double)(event.resolution.getScaledWidth() / 2), (double)(event.resolution.getScaledHeight() / 2), 0.0D);          GL11.glPushMatrix();          ClientProxy.iconRegistry.bindSheet();          GL11.glRotated(90.0D, 0.0D, 0.0D, 2.0D);          ClientProxy.iconRegistry.renderIcon(crosshairIcon, -1.9D, (double)(-scale) + 0.1D);          GL11.glRotated(90.0D, 0.0D, 0.0D, 1.0D);          ClientProxy.iconRegistry.renderIcon(crosshairIcon, -3.0D, (double)(-scale) - 0.1D);          GL11.glRotated(90.0D, 0.0D, 0.0D, 1.0D);          ClientProxy.iconRegistry.renderIcon(crosshairIcon, -3.0D, (double)(-scale) + 0.9D);                    if(FlansModClient.currentScope == null)                        {          GL11.glRotated(90.0D, 0.0D, 0.0D, 1.0D);          ClientProxy.iconRegistry.renderIcon(crosshairIcon, -2.1D, (double)(-scale) + 0.9D);          }                    else if (scale >= 6.5F)          {          GL11.glRotated(90.0D, 0.0D, 0.0D, 1.0D);          ClientProxy.iconRegistry.renderIcon(crosshairIcon, -2.1D, (double)(-scale) + 0.9D);          }                    GL11.glPopMatrix();          GL11.glPopMatrix();          GL11.glPopAttrib();          minecraft.getTextureManager().bindTexture(Gui.icons);       }       }    }
    • Hello, I'm working on my first Minecraft 1.20.2 mod. However, I've created a custom block model and everything works perfectly except the rotation of the block. The code is implemented but it still doesnt work. Need help. This is the code of the object class. import net.minecraft.core.BlockPos; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.Mirror; public class DirtyRock extends HorizontalDirectionalBlock { public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 2, 11); public DirtyRock(Properties pProperties) { super(pProperties); } @Override public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { return SHAPE; } @Override public BlockState getStateForPlacement(BlockPlaceContext pContext) { return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite()); } @Override public BlockState rotate(BlockState pState, Rotation pRot) { return pState.setValue(FACING, pRot.rotate(pState.getValue(FACING))); } @Override public BlockState mirror(BlockState pState, Mirror pMirror) { return pState.rotate(pMirror.getRotation(pState.getValue(FACING))); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) { pBuilder.add(FACING); } } In the ModBlocks class the block is registred like this public static final RegistryObject<Block> DIRTY_ROCK=registerBlock("dirty_rock", ()-> new DirtyRock(BlockBehaviour.Properties.copy(Blocks.STONE_BUTTON))); private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block){ RegistryObject<T> toReturn=BLOCKS.register(name,block); registerBlockItem(name,toReturn); return toReturn; } In the Data, ModBlockStateProvider the blockstate is implemened simpleBlock(ModBlocks.DIRTY_ROCK.get(), new ModelFile.UncheckedModelFile(modLoc("block/dirty_rock"))); And in resources/assets/modname/models/block dirty_rock.json is implemented { "credit": "Made with Blockbench", "textures": { "0": "wildandhunt:block/dirty_bricks_block", "particle": "wildandhunt:block/dirty_bricks_block" }, "elements": [ { "from": [5, 0, 4], "to": [9, 1, 8], "rotation": {"angle": 22.5, "axis": "y", "origin": [10, 0, 7]}, "faces": { "north": {"uv": [5, 4, 10, 5], "texture": "#0"}, "east": {"uv": [5, 5, 10, 6], "texture": "#0"}, "south": {"uv": [5, 6, 10, 7], "texture": "#0"}, "west": {"uv": [5, 7, 10, 8], "texture": "#0"}, "up": {"uv": [5, 5, 0, 0], "texture": "#0"}, "down": {"uv": [5, 5, 0, 10], "texture": "#0"} } }, { "from": [9, 0, 4.05], "to": [11, 2, 6.05], "rotation": {"angle": 22.5, "axis": "y", "origin": [8, 0, 9]}, "faces": { "north": {"uv": [5, 4, 10, 5], "texture": "#0"}, "east": {"uv": [5, 5, 10, 6], "texture": "#0"}, "south": {"uv": [5, 6, 10, 7], "texture": "#0"}, "west": {"uv": [5, 7, 10, 8], "texture": "#0"}, "up": {"uv": [5, 5, 0, 0], "texture": "#0"}, "down": {"uv": [5, 5, 0, 10], "texture": "#0"} } }, { "from": [5, 0, 7], "to": [6, 1, 8], "rotation": {"angle": 22.5, "axis": "y", "origin": [10, 0, 10]}, "faces": { "north": {"uv": [5, 4, 10, 5], "texture": "#0"}, "east": {"uv": [5, 5, 10, 6], "texture": "#0"}, "south": {"uv": [5, 6, 10, 7], "texture": "#0"}, "west": {"uv": [5, 7, 10, 8], "texture": "#0"}, "up": {"uv": [5, 5, 0, 0], "texture": "#0"}, "down": {"uv": [5, 5, 0, 10], "texture": "#0"} } }, { "from": [10, 0, 8], "to": [12, 1, 9], "rotation": {"angle": 22.5, "axis": "y", "origin": [15, 0, 11]}, "faces": { "north": {"uv": [5, 4, 10, 5], "texture": "#0"}, "east": {"uv": [5, 5, 10, 6], "texture": "#0"}, "south": {"uv": [5, 6, 10, 7], "texture": "#0"}, "west": {"uv": [5, 7, 10, 8], "texture": "#0"}, "up": {"uv": [5, 5, 0, 0], "texture": "#0"}, "down": {"uv": [5, 5, 0, 10], "texture": "#0"} } }, { "from": [9.4, 0, 5], "to": [12.4, 1, 8.5], "rotation": {"angle": 22.5, "axis": "y", "origin": [12, 0, 7]}, "faces": { "north": {"uv": [8, 0, 11, 1], "texture": "#0"}, "east": {"uv": [8, 2, 10, 3], "texture": "#0"}, "south": {"uv": [8, 1, 11, 2], "texture": "#0"}, "west": {"uv": [8, 3, 10, 4], "texture": "#0"}, "up": {"uv": [8, 2, 5, 0], "texture": "#0"}, "down": {"uv": [8, 2, 5, 4], "texture": "#0"} } }, { "from": [6, 1, 6], "to": [10, 1.75, 10], "rotation": {"angle": 22.5, "axis": "y", "origin": [9, 0, 7]}, "faces": { "north": {"uv": [8, 0, 11, 1], "texture": "#0"}, "east": {"uv": [8, 2, 10, 3], "texture": "#0"}, "south": {"uv": [8, 1, 11, 2], "texture": "#0"}, "west": {"uv": [8, 3, 10, 4], "texture": "#0"}, "up": {"uv": [8, 2, 5, 0], "texture": "#0"}, "down": {"uv": [8, 2, 5, 4], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [0, 7.75, 0] }, "thirdperson_lefthand": { "translation": [0, 7.75, 0] }, "firstperson_righthand": { "translation": [0, 8.25, 0] }, "firstperson_lefthand": { "translation": [0, 8.25, 0] }, "ground": { "translation": [0, 4, 0] }, "gui": { "rotation": [32, 32, 9], "translation": [-1.25, 6.25, 0], "scale": [1.31, 1.31, 1.31] }, "fixed": { "translation": [0, 6.75, 0] } }, "groups": [ { "name": "dirty_stone", "origin": [8, 0, 7], "color": 0, "children": [0, 1, 2, 3, 4, 5] } ] }  
    • has anyone encountered an issue where they have the same mod installed on client and server but when the client tries to join the server the client disconnects immediately and gives this `Internal Exception: io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: -1` while the problem exists only when the mod is loaded? Repo: https://github.com/Type-32/PreciseManufacturing/tree/1.20.1 Forge 1.20.1 Mod, logs gives no useful info, but I'm still gonna put it here Server logs: https://pastebin.com/SUBbg0fF No client logs here because when client disconnects it only shows that is has disconnected, and nothing more  
  • Topics

×
×
  • Create New...

Important Information

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