Non résolu [1.12.2] J'ai besoin d'aide svp (block avec gui)
-
quand je fait SHIFT + CLICK (n’importe ou dans les case)
sa fait cracher le jeux MINECRAFT
sa serais possible de m’aider ?
-
Bonsoir,
J’ai déplacé dans la section support pour les moddeurs. Merci de poster toutes futurs demande d’aide lié à la programmation dans cette section et non dans discussion général.Merci également d’utiliser les balises appropriés pour les logs plutôt que les images.
Pour la deuxième erreur que tu as, tu as oublié d’enregistrer le tile entity.
Concernant la première erreur il faudrait ton code pour déterminer le problème. -
Je lais fait ici
@EventHandler public void init(FMLInitializationEvent event) { proxy.init(); FamilygameRecipe.init(); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); GameRegistry.registerTileEntity(TileEntityCrate.class, new ResourceLocation(MODID, "TileEntityCrate")); }
Class BlockCrate
package fr.thexrayfr.familygame.blocks; import fr.thexrayfr.familygame.Main; import fr.thexrayfr.familygame.tile.TileEntityCrate; import net.minecraft.block.BlockPlanks.EnumType; import net.minecraft.block.BlockPlanks; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumDyeColor; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockCrate extends BlockBase { public BlockCrate(String name, Material material) { super(name, material); this.setCreativeTab(Main.TABFAMILYGAME); this.setHardness(2.0F); this.setResistance(5.0F); this.setSoundType(SoundType.WOOD); } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityCrate(); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { playerIn.openGui(Main.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ()); return false; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } }
Class TileEntityCrate
package fr.thexrayfr.familygame.tile; import net.minecraft.block.BlockPlanks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; public class TileEntityCrate extends TileEntity implements IInventory { private NonNullList<ItemStack> stacks = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); protected String customName; @Override public String getName() { return null; } @Override public boolean hasCustomName() { return false; } public int getSizeInventory() { return 27; } public boolean isEmpty() { for (ItemStack itemstack : this.stacks) { if (!itemstack.isEmpty()) { return false; } } return true; } @Override public ItemStack getStackInSlot(int index) { return this.stacks.get(index); } @Override public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.stacks, index, count); } @Override public ItemStack removeStackFromSlot(int index) { this.stacks.set(index, ItemStack.EMPTY); return this.getStackInSlot(index); } @Override public void setInventorySlotContents(int index, ItemStack stack) { this.stacks.set(index, stack); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUsableByPlayer(EntityPlayer player) { if (this.world.getTileEntity(this.pos) != this) { return false; } else { return player.getDistanceSq((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D, (double) this.pos.getZ() + 0.5D) <= 64.0D; } } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { this.stacks.clear(); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); ItemStackHelper.loadAllItems(compound, this.stacks); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { ItemStackHelper.saveAllItems(compound, this.stacks); return super.writeToNBT(compound); } }
class GuiCrate
package fr.thexrayfr.familygame; import org.lwjgl.opengl.GL11; import fr.thexrayfr.familygame.container.ContainerOakCrate; import fr.thexrayfr.familygame.tile.TileEntityCrate; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; public class GuiCrate extends GuiContainer { private static final ResourceLocation textures = new ResourceLocation(Main.MODID, "textures/gui/container/gui_crate_container.png"); private TileEntityCrate tileTuto; private IInventory playerInv; public GuiCrate(TileEntityCrate tile, InventoryPlayer inventory) { super(new ContainerOakCrate(tile, inventory)); this.tileTuto = tile; this.playerInv = inventory; this.allowUserInput = false; this.ySize = 170; } @Override protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); // on colorise this.mc.getTextureManager().bindTexture(textures); // affiche la texture int k = (this.width - this.xSize) / 2; // on calcul la coordonnée x du point en haut à gauche int l = (this.height - this.ySize) / 2; // on calcul la coordonnée y du point en haut à gauche this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); // on desine la texture, la fonction à pour argument point x de départ, point y de départ, vecteur u, vecteur v, largeur, hauteur) } }
class gui Hnadler
package fr.thexrayfr.familygame; import fr.thexrayfr.familygame.container.ContainerOakCrate; import fr.thexrayfr.familygame.tile.TileEntityCrate; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.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 tile = world.getTileEntity(new BlockPos(x, y, z)); if (ID == 0) { return new ContainerOakCrate((TileEntityCrate) tile, player.inventory); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(new BlockPos(x, y, z)); if (ID == 0) { return new GuiCrate((TileEntityCrate) tile, player.inventory); } return null; } }
-
et sa enregistre pas les block dans le gui quand je quitte et revient dans le monde