Résolu Bloc (type machine) ne fonctionne pas
-
Je voulais faire une machine qui dans son fonctionnement ressemble à un four, je peux poser le bloc mais quand je clique dessus aucune GUI ne s’ouvre et je ne peux pas mettre d’item à l’intérieur via un hopper. Nom du bloc : UPGRADE_ARMOR_MACHINE .
Classe principale :
package fr.dragoniadev.dragoniamod; import org.apache.logging.log4j.Logger; import fr.dragoniadev.dragoniamod.common.block.tileentity.TileEntityUpgradeArmorMachine; import fr.dragoniadev.dragoniamod.common.events.RegisteringHandler; import fr.dragoniadev.dragoniamod.common.item.DragoniaModItems; import fr.dragoniadev.dragoniamod.common.world.WorldGeneration; import fr.dragoniadev.dragoniamodcommon.gui.GuiHandler; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @Mod(modid = DragoniaMod.MODID, name = "Dragonia Mod", version = "1.0") public class DragoniaMod { public static final String MODID = "dragoniamod"; @Instance(DragoniaMod.MODID) public static DragoniaMod instance; @SidedProxy(clientSide = "fr.dragoniadev.dragoniamod.DragoniaModClient", serverSide = "fr.dragoniadev.dragoniamod.DragoniaModServer") public static DragoniaModCommon proxy; public static Logger logger; WorldGeneration worldgeneration = new WorldGeneration(); public static final CreativeTabs DRAGONIA = new CreativeTabs("dragonia") { @Override @SideOnly(Side.CLIENT) public ItemStack getTabIconItem() { return new ItemStack(DragoniaModItems.DARKFIRE_INGOT); } }; @EventHandler public void preInit(FMLPreInitializationEvent event){ logger = event.getModLog(); proxy.preInit(event.getSuggestedConfigurationFile()); GameRegistry.registerWorldGenerator(worldgeneration, 0); GameRegistry.registerTileEntity(TileEntityUpgradeArmorMachine.class, new ResourceLocation(MODID, "TileEntityUpgradeArmorMachine")); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); } @EventHandler public void init(FMLInitializationEvent event){ proxy.init(); } public DragoniaMod() { MinecraftForge.EVENT_BUS.register(new RegisteringHandler()); } }
Classe des blocs :
package fr.dragoniadev.dragoniamod.common.block; import fr.dragoniadev.dragoniamod.DragoniaMod; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = DragoniaMod.MODID) public class DragoniaModBlocks { public static final Block DARKONIA_ORE = new BlockDarkoniaOre(Material.ROCK); public static final Block DARKONIA_BLOCK = new BlockDarkonia(Material.IRON); public static final Block TITANIUM_ORE = new BlockTitaniumOre(Material.ROCK); public static final Block TITANIUM_BLOCK = new BlockTitanium(Material.IRON); public static final Block COMMON_XP_ORE = new BlockCommonXpOre(Material.ROCK); public static final Block UNCOMMON_XP_ORE = new BlockUnCommonXpOre(Material.ROCK); public static final Block LEGENDARY_XP_ORE = new BlockLegendaryXpOre(Material.ROCK); public static final Block RANDOM_GEM_ORE = new BlockRandomGemOre(Material.ROCK); public static final Block PLAYER_HOLOGRAM = new BlockPlayerHologram(Material.GLASS); public static final Block UPGRADE_ARMOR_MACHINE = new BlockUpgradeArmorMachine(Material.ANVIL); public static void setBlockName(Block block, String name) { block.setRegistryName(DragoniaMod.MODID, name).setUnlocalizedName(DragoniaMod.MODID + "." + name); } }
Classe du Bloc :
package fr.dragoniadev.dragoniamod.common.block; import fr.dragoniadev.dragoniamod.DragoniaMod; import fr.dragoniadev.dragoniamod.common.block.tileentity.TileEntityUpgradeArmorMachine; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockUpgradeArmorMachine extends Block { public static final String UPGRADE_ARMOR_MACHINE = "upgrade_armor_machine"; public BlockUpgradeArmorMachine(Material materialIn) { super(materialIn); DragoniaModBlocks.setBlockName(this, UPGRADE_ARMOR_MACHINE); setResistance(5.0F); setHardness(15.0F); setCreativeTab(DragoniaMod.DRAGONIA); } @Override public boolean hasTileEntity() { return true; } public TileEntity createNewTileEntity(World world, int metadata) { return new TileEntityUpgradeArmorMachine(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityUpgradeArmorMachine) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityUpgradeArmorMachine) tileentity); } super.breakBlock(worldIn, pos, state); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { TileEntity tileentity = world.getTileEntity(pos); if (tileentity instanceof TileEntityUpgradeArmorMachine) { player.openGui(DragoniaMod.instance, 0, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } }
Classe du container :
package fr.dragoniadev.dragoniamod.common.block.container; import fr.dragoniadev.dragoniamod.common.block.container.slot.DragoniaModSlotOutput; import fr.dragoniadev.dragoniamod.common.block.container.slot.DragoniaModSlotSingleItem; import fr.dragoniadev.dragoniamod.common.block.tileentity.TileEntityUpgradeArmorMachine; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.IContainerListener; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ContainerUpgradeArmorMachine extends Container { private TileEntityUpgradeArmorMachine tile; private int timePassed = 0; private int burnTimeLeft = 0; public ContainerUpgradeArmorMachine(TileEntityUpgradeArmorMachine tile, InventoryPlayer playerInventory) { this.tile = tile; int i; for(i = 0; i < 2; i++) { this.addSlotToContainer(new Slot(tile, i, 33 + i * 18, 7)); } for(i = 0; i < 2; i++) { this.addSlotToContainer(new DragoniaModSlotSingleItem(tile, i + 2, 42, 40 + i * 18, i == 0 ? Item.getItemFromBlock(Blocks.PLANKS) : Items.WHEAT)); } this.addSlotToContainer(new DragoniaModSlotOutput(tile, 4, 116, 17)); for(i = 0; i < 3; ++i) { for(int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for(i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer player) { return tile.isUsableByPlayer(player); } @Override public void addListener(IContainerListener listener) { super.addListener(listener); listener.sendAllWindowProperties(this, this.tile); } @Override public void detectAndSendChanges() { super.detectAndSendChanges(); for(int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener) this.listeners .get(i); if (this.burnTimeLeft != this.tile.getField(0)) { icontainerlistener.sendWindowProperty(this, 0, this.tile.getField(0)); } if (this.timePassed != this.tile.getField(1)) { icontainerlistener.sendWindowProperty(this, 1, this.tile.getField(1)); } } this.burnTimeLeft = this.tile.getField(0); this.timePassed = this.tile.getField(1); } @Override @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tile.setField(id, data); } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { return ItemStack.EMPTY; } }
Classe du TileEntity :
package fr.dragoniadev.dragoniamod.common.block.tileentity; import fr.dragoniadev.dragoniamod.common.item.DragoniaModItems; import fr.dragoniadev.dragoniamod.common.recipes.RecipesUpgradeArmorMachine; import net.minecraft.util.ITickable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.util.NonNullList; import net.minecraftforge.oredict.OreDictionary; public class TileEntityUpgradeArmorMachine extends TileEntityLockable implements ITickable { private NonNullList<ItemStack> stacks = NonNullList.withSize(5, ItemStack.EMPTY); private String customName; private int timePassed = 0; private int burningTimeLeft = 0; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.stacks = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY); ItemStackHelper.loadAllItems(compound, this.stacks); if (compound.hasKey("CustomName", 8)) { this.customName = compound.getString("CustomName"); } this.burningTimeLeft = compound.getInteger("burningTimeLeft"); this.timePassed = compound.getInteger("timePassed"); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); ItemStackHelper.saveAllItems(compound, this.stacks); if (this.hasCustomName()) { compound.setString("CustomName", this.customName); } compound.setInteger("burningTimeLeft", this.burningTimeLeft); compound.setInteger("timePassed", this.timePassed); return compound; } @Override public int getField(int id) { switch (id) { case 0: return this.burningTimeLeft; case 1: return this.timePassed; } return 0; } @Override public void setField(int id, int value) { switch (id) { case 0: this.burningTimeLeft = value; break; case 1: this.timePassed = value; } } @Override public int getFieldCount() { return 2; } @Override public int getSizeInventory() { return this.stacks.size(); } @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) { return ItemStackHelper.getAndRemove(stacks, index); } @Override public void setInventorySlotContents(int index, ItemStack stack) { this.stacks.set(index, stack); if (stack.getCount() > this.getInventoryStackLimit()) { stack.setCount(this.getInventoryStackLimit()); } } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isEmpty() { for(ItemStack stack : this.stacks) { if (!stack.isEmpty()) { return false; } } return true; } @Override public void clear() { for(int i = 0; i < this.stacks.size(); i++) { this.stacks.set(i, ItemStack.EMPTY); } } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) {} @Override public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return null; } @Override public String getGuiID() { return null; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { if ( index == 0) return true; if (index == 1) return true; if (index == 2) return OreDictionary.getOres("blockCoal").contains( new ItemStack(stack.getItem(), 1, OreDictionary.WILDCARD_VALUE)); if (index == 3) return stack.getItem() == DragoniaModItems.TITANIUM_HAMMER; if (index == 4) return false; return true; } @Override public boolean isUsableByPlayer(EntityPlayer player) { return this.world.getTileEntity(this.pos) != this ? false : player .getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D; } public boolean hasFuelEmpty() { return this.getStackInSlot(2).isEmpty(); } public ItemStack getRecipeResult() { return RecipesUpgradeArmorMachine.getRecipeResult(new ItemStack[] { this.getStackInSlot(0), this.getStackInSlot(1), this.getStackInSlot(3) }); } public boolean canSmelt() { ItemStack result = this.getRecipeResult(); if (result != null) { ItemStack slot4 = this.getStackInSlot(4); if (slot4.isEmpty()) return true; if (slot4.getItem() == result.getItem() && slot4.getItemDamage() == result.getItemDamage()) { int newStackSize = slot4.getCount() + result.getCount(); if (newStackSize <= this.getInventoryStackLimit() && newStackSize <= slot4.getMaxStackSize()) { return true; } } } return false; } public void smelt() { ItemStack result = this.getRecipeResult(); this.decrStackSize(0, 1); this.decrStackSize(1, 1); ItemStack stack4 = this.getStackInSlot(4); if (stack4.isEmpty()) { this.setInventorySlotContents(4, result.copy()); } else { stack4.setCount(stack4.getCount() + result.getCount()); } } public int getFullRecipeTime() { return 1000; } public int getFullBurnTime() { return 1000; } public boolean isBurning() { return burningTimeLeft > 0; } public void update() { if (!this.world.isRemote) { if (this.isBurning()) { this.burningTimeLeft--; } if (!this.isBurning() && this.canSmelt() && !this.hasFuelEmpty()) { this.burningTimeLeft = this.getFullBurnTime(); this.decrStackSize(2, 1); this.decrStackSize(3, 1); } if (this.isBurning() && this.canSmelt()) { this.timePassed++; if (timePassed >= this.getFullRecipeTime()) { timePassed = 0; this.smelt(); } } else { timePassed = 0; } this.markDirty(); } } @Override public String getName() { // TODO Auto-generated method stub return null; } @Override public boolean hasCustomName() { // TODO Auto-generated method stub return false; } }
Les recipes :
package fr.dragoniadev.dragoniamod.common.recipes; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import fr.dragoniadev.dragoniamod.common.item.DragoniaModItems; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class RecipesUpgradeArmorMachine { private static final HashMap <ItemStack[], ItemStack>recipes = new HashMap<ItemStack[], ItemStack>(); static { addRecipe(DragoniaModItems.RUBY, Items.DIAMOND_HELMET, DragoniaModItems.TITANIUM_HAMMER, Items.APPLE); } private static void addRecipe(Item ingredient1, Item ingredient2, Item ingredient3, Item resultat1) { addRecipe(new ItemStack(ingredient1), new ItemStack(ingredient2), new ItemStack(ingredient3), new ItemStack(resultat1)); } private static void addRecipe(ItemStack ingredient1, ItemStack ingredient2, ItemStack ingredient3, ItemStack resultat1) { recipes.put(new ItemStack[]{ingredient1, ingredient2, ingredient3}, resultat1); } private static boolean areKeysEqual(ItemStack[] key1, ItemStack[] key2) { if(key1.length != key2.length) return false; for(int i = 0; i < key1.length; i++) { ItemStack s1 = key1[i]; ItemStack s2 = key2[i]; if(s1.isEmpty() && !s2.isEmpty()) return false; if(!s1.isEmpty() && s2.isEmpty()) return false; if(s1.getItem() != s2.getItem()) return false; if(s1.getItemDamage() != s2.getItemDamage()) return false; } return true; } public static ItemStack getRecipeResult(ItemStack[] ingredients) { Iterator<Entry<ItemStack[], ItemStack>> it = recipes.entrySet().iterator(); while(it.hasNext()) { Entry <ItemStack[], ItemStack>entry = it.next(); if(areKeysEqual(entry.getKey(), ingredients)) { return entry.getValue(); } } return null; } }
La GUI du bloc :
package fr.dragoniadev.dragoniamod.client.gui; import fr.dragoniadev.dragoniamod.common.block.container.ContainerUpgradeArmorMachine; import fr.dragoniadev.dragoniamod.common.block.tileentity.TileEntityUpgradeArmorMachine; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; public class GuiUpgradeArmorMachine extends GuiContainer { private static final ResourceLocation background = new ResourceLocation("dragoniamod","textures/gui/container/upgrade_armor_machine.png"); private TileEntityUpgradeArmorMachine tile; public GuiUpgradeArmorMachine(TileEntityUpgradeArmorMachine tile, InventoryPlayer playerInv) { super(new ContainerUpgradeArmorMachine(tile, playerInv)); this.tile = tile; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { int i = (this.width - this.xSize) / 2; int j = (this.height - this.ySize) / 2; this.drawDefaultBackground(); this.mc.getTextureManager().bindTexture(background); this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize); int timePassed = this.tile.getField(1); int textureWidth = (int) (23f / 200f * timePassed); this.drawTexturedModalRect(i + 81, j + 24, 177, 18, textureWidth, 7); if (this.tile.isBurning()) { int burningTime = this.tile.getField(0); int textureHeight = (int) (12f / this.tile.getFullBurnTime() * burningTime); this.drawTexturedModalRect(i + 37, j + 26 + 12 - textureHeight, 177, 12 - textureHeight, 27, textureHeight); } this.fontRenderer.drawString(this.tile.getName(), i + 80, j + 45, 0xFFFFFF); } }
Et enfin le GuiHandler :
package fr.dragoniadev.dragoniamodcommon.gui; import fr.dragoniadev.dragoniamod.client.gui.GuiUpgradeArmorMachine; import fr.dragoniadev.dragoniamod.common.block.container.ContainerUpgradeArmorMachine; import fr.dragoniadev.dragoniamod.common.block.tileentity.TileEntityUpgradeArmorMachine; 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 te = world.getTileEntity(new BlockPos(x, y, z)); if(te instanceof TileEntityUpgradeArmorMachine) { return new ContainerUpgradeArmorMachine((TileEntityUpgradeArmorMachine)te, player.inventory); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if(te instanceof TileEntityUpgradeArmorMachine) { return new GuiUpgradeArmorMachine((TileEntityUpgradeArmorMachine)te, player.inventory); } return null; } }
J’ai conscience que ce post est long, mais ça fait des heures que je me casse la tête dessus
Merci d’une réponse prochaine
-
Classe du bloc:
import com.Nugarium.NuagrMod.NugarMod; import com.Nugarium.NuagrMod.init.BlockMod; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import javax.annotation.Nullable; public class BlockUpgradeArmorMachine extends BlockContainer { public static final String UPGRADE_ARMOR_MACHINE = "NUGARMACHINE"; public BlockUpgradeArmorMachine(Material materialIn) { super(materialIn); BlockMod.setBlockName(this, UPGRADE_ARMOR_MACHINE); setResistance(5.0F); setHardness(15.0F); setCreativeTab(NugarMod.NUGAR); } @Override public boolean hasTileEntity() { return true; } @Nullable @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityUpgradeArmorMachine(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityUpgradeArmorMachine) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityUpgradeArmorMachine) tileentity); } super.breakBlock(worldIn, pos, state); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { player.openGui(NugarMod.instance, 1, world, pos.getX(), pos.getY(), pos.getZ()); return true; } } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } }
GuiHandler:
import com.Nugarium.NuagrMod.machine.ContainerUpgradeArmorMachine; import com.Nugarium.NuagrMod.machine.GuiUpgradeArmorMachine; import com.Nugarium.NuagrMod.machine.TileEntityUpgradeArmorMachine; 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) { switch(ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new ContainerUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new GuiUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } }
-
Bonsoir,
Ajoutes un @Override
au dessous depublic TileEntity createNewTileEntity(World world, int metadata) {
pour voir ? -
Ca me met une erreur
The method createNewTileEntity(World, int) of type BlockUpgradeArmorMachine must override or implement a supertype method -
Donc tu n’as pas le bon nom.
Regardes dans la classe Block.java. -
Ok, je regarderais ça demain, j’ai une épreuve blanche je dois me coucher, Bonne nuit !
-
J’ai changé la fonction en create TileEntity mais toujours rien :
@Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityUpgradeArmorMachine(); }
-
Tu as cassé puis reposé le bloc ?
-
Bonjour je suis dans la même situation que toi mais je crois avoir trouvé la solution , dans ta TileEntity tu as Normalement Update si tu as suivie le tuto du four 1.11 , 1.12 mais le problème c’est qu’en 1.12.2 je crois que Update s appelle en faite tick() et pas update() mais moi la je peux pas tester donc je ne sais pas si ça marche :)EDIT: je suis bete j avais juste mal extends mon ITickable il faut mettre
import net.minecraft.util.ITickable;
Edit , moi ca marche soluce trouvé
dans la classe de ton block met juste ca@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { player.openGui(NugarMod.instance, 0, world, pos.getX(), pos.getY(), pos.getZ()); return true; } }
-
Je l’avais déjà mise dans ma classe mais merci quand même !
-
non enfaite dans tas classe y a
if (tileentity instanceof TileEntityUpgradeArmorMachine) { player.openGui(DragoniaMod.instance, 0, world, pos.getX(), pos.getY(), pos.getZ()); }
et la condition if bloque tout faut juste le mettre dans else
Edit car sinon je peux pas de répondre:
tu as extend ta classe a BlockContainer ? -
Ca ne fonctionne pas non plus
-
tu a bien extends ta classe a BlockContainer et si oui et que ca marche toujours pas bah tu met
ca dans la classe de ton block@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { player.openGui(NugarMod.instance, 1, world, pos.getX(), pos.getY(), pos.getZ()); return true; } }
et ca c est ton nouveau GuiHandler :
public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new ContainerUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new GuiUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } }
-
BlockContainer ou Container ?
-
non au lieu d extend la classe de ton block a Block tu remplace pas extends BlockContainer
-
Toujours pas je renvoie les classes modifiées ?
-
Classe du bloc:
import com.Nugarium.NuagrMod.NugarMod; import com.Nugarium.NuagrMod.init.BlockMod; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import javax.annotation.Nullable; public class BlockUpgradeArmorMachine extends BlockContainer { public static final String UPGRADE_ARMOR_MACHINE = "NUGARMACHINE"; public BlockUpgradeArmorMachine(Material materialIn) { super(materialIn); BlockMod.setBlockName(this, UPGRADE_ARMOR_MACHINE); setResistance(5.0F); setHardness(15.0F); setCreativeTab(NugarMod.NUGAR); } @Override public boolean hasTileEntity() { return true; } @Nullable @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityUpgradeArmorMachine(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityUpgradeArmorMachine) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityUpgradeArmorMachine) tileentity); } super.breakBlock(worldIn, pos, state); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { player.openGui(NugarMod.instance, 1, world, pos.getX(), pos.getY(), pos.getZ()); return true; } } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } }
GuiHandler:
import com.Nugarium.NuagrMod.machine.ContainerUpgradeArmorMachine; import com.Nugarium.NuagrMod.machine.GuiUpgradeArmorMachine; import com.Nugarium.NuagrMod.machine.TileEntityUpgradeArmorMachine; 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) { switch(ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new ContainerUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 1: TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te instanceof TileEntityUpgradeArmorMachine) { return new GuiUpgradeArmorMachine((TileEntityUpgradeArmorMachine) te, player.inventory); } default: return null; } } }
-
Oww !!! SUPER MERCI !! + 1 de réputation !