Jump to content

Wasylews

Members
  • Posts

    7
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Wasylews's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Don't need use ".name", ok. Thank you for fast response.
  2. I'm trying to localize text of my button: GuiButton(1, 10, 10, 20, 20, StatCollector.translateToLocal("mybutton") in en_US.lang I write but this not working, in gui I get "mybutton", why?
  3. Guys, please help me! Why I can't drag items in my inventory? If I click on item, he appears in world. But if I click on item's top, I can drag item to inventory
  4. Thanks, but it doesn't work. The code from wiki worked while I didn't change layout of a texture and slots. Problem, likely, in this code @Override public boolean isUseableByPlayer(EntityPlayer player) { TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord); double dist = player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); return te == this && dist < 64; } How i can calculate this constant for coordinates? No, not here. Anybody can help?
  5. I took a code with www.minecraftforge.net/wiki/Containers_and_GUIs, remade coordinates for a texture 256x256. But after that subjects from stock of the player, when clicking them, appear in a pattern, instead of are dragged. I likely somewhere forgot to correct a constant? [spoiler=MyGui] package com.mymod; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; public class MyGui extends GuiContainer { public static final int GUI_ID = 20; final int xSize = 256; final int ySize = 256; public MyGui(InventoryPlayer inventoryPlayer, MyTileEntity tileEntity) { //the container is instanciated and passed to the superclass for handling super(new MyContainer(inventoryPlayer, tileEntity)); } @Override protected void drawGuiContainerForegroundLayer(int param1, int param2) { //draw text and stuff here } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(new ResourceLocation(MyMod.MOD_ID, "textures/gui/sell.png")); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, xSize, ySize); } @Override public void initGui() { super.initGui(); this.guiLeft = (this.width - this.xSize) / 2 + 40; this.guiTop = (this.height - this.ySize) / 2 + 30; } } [spoiler=MyContainer] package com.mymod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class MyContainer extends Container { protected MyTileEntity tileEntity; public MyContainer (InventoryPlayer inventoryPlayer, MyTileEntity te){ tileEntity = te; //the Slot constructor takes the IInventory and the slot number in that it binds to //and the x-y coordinates it resides on-screen int id, x, y; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { id = j + i * 3; x = 9 + j * 18; y = 44 + i * 18; addSlotToContainer(new MySlot(tileEntity, id, x, y)); } } //commonly used vanilla code that adds the player's inventory bindPlayerInventory(inventoryPlayer); } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { int id, x, y; for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { id = j + i * 9 + 9; x = 8 + j * 18; y = 106 + i * 18; addSlotToContainer(new Slot(inventoryPlayer, id, x, y)); } } y = 164; for (int i = 0; i < 9; i++) { x = 8 + i * 18; addSlotToContainer(new Slot(inventoryPlayer, i, x, y)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tileEntity if (slot < 9) { if (!this.mergeItemStack(stackInSlot, 0, 36, true)) { return null; } } //places it into the tileEntity is possible since its in the player inventory else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } return stack; } } [spoiler=MyTileEntity] package com.mymod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class MyTileEntity extends TileEntity implements IInventory { private ItemStack[] inv; public MyTileEntity(){ inv = new ItemStack[9]; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { return inv[slot]; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } } @Override public String getInventoryName() { return "My.tileentity"; } @Override public boolean hasCustomInventoryName() { return false; } @Override public ItemStack decrStackSize(int slot, int amt) { ItemStack stack = getStackInSlot(slot); setInventorySlotContents(slot, null); if (stack != null) { if (stack.stackSize <= amt) { setInventorySlotContents(slot, null); } else { stack = stack.splitStack(amt); if (stack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord); double dist = player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); return te == this && dist < 64; } @Override public void openInventory() { //To change body of implemented methods use File | Settings | File Templates. } @Override public void closeInventory() { //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return false; } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory", ; for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = tagList.getCompoundTagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } } [spoiler=MySlot] package com.mymod; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class MySlot extends Slot { private static ItemStack validType; private IInventory inv; public MySlot(IInventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); inv = p_i1824_1_; } @Override public boolean isItemValid(ItemStack stack) { if (validType == null) { validType = stack.copy(); } return (stack.isItemEqual(MySlot.validType)); } @Override public void onSlotChanged() { super.onSlotChanged(); if (invIsEmpty()) { MySlot.validType = null; } } private boolean invIsEmpty() { for (int i = 0; i < inv.getSizeInventory(); ++i) { if (inv.getStackInSlot(i) != null) { return false; } } return true; } } [spoiler=MyBlock] package com.mymod; 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.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; 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; import net.minecraft.util.IIcon; import net.minecraft.world.World; import java.util.Random; public class MyBlock extends BlockContainer { private IIcon[] icons = new IIcon[6]; public MyBlock() { super(Material.iron); this.setBlockName("Myblock"); this.setCreativeTab(CreativeTabs.tabMisc); this.setBlockTextureName("mymod:Myblock"); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()) { return false; } player.openGui(My.instance, MyGui.GUI_ID, world, x, y, z); return true; } @Override public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { dropItems(world, x, y, z); super.breakBlock(world, x, y, z, par5, par6); } private void dropItems(World world, int x, int y, int z){ Random rand = new Random(); TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.getItem(), item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } } @Override public void registerBlockIcons(IIconRegister reg) { for (int i = 0; i < 6; i ++) { this.icons[i] = reg.registerIcon(this.textureName + "_" + i); } } @Override public IIcon getIcon(int side, int meta) { return this.icons[side]; } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return new MyTileEntity(); } }
  6. Thanks, this is working. And if I want to make craft system, I need create Container? Can you show me a simple example?
  7. Hi guys. I want to make custom gui for my block, but gui doesn't open. Here is code [spoiler=MyMod.java] package com.mymod; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @Mod(modid = MyMod.MODID, version = MyMod.VERSION) public class MyMod { public static final String MODID = "MyMod"; public static final String VERSION = "1.0"; @Mod.Instance(MyMod.MODID) public static MyMod instance; public static Logger log = Logger.getLogger("Minecraft"); public static Block MyModBlock; public MyMod() { instance = this; } @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { MyModBlock = new MyModBlock(); GameRegistry.registerBlock(MyModBlock, "MyModBlock"); GameRegistry.addRecipe(new ItemStack(MyModBlock), new Object[]{"###", "## ", "###", Character.valueOf('#'), Items.iron_ingot}); NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); log.info("MyMod loaded."); } } [spoiler=MyBlock.java] package com.MyMod; 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.player.EntityPlayer; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class MyModBlock extends Block { private IIcon[] icons = new IIcon[6]; public MyModBlock() { super(Material.iron); this.setBlockName("MyModblock"); this.setCreativeTab(CreativeTabs.tabMisc); this.setBlockTextureName("MyMod:MyModblock"); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ if (!world.isRemote) { System.out.print("block clicked, open gui.\n"); System.out.print(MyMod.instance != null); player.openGui(MyMod.instance, Gui.GUI_ID, world, x, y, z); } return true; } @Override public void registerBlockIcons(IIconRegister reg) { for (int i = 0; i < 6; i ++) { this.icons[i] = reg.registerIcon(this.textureName + "_" + i); } } @Override public IIcon getIcon(int side, int meta) { return this.icons[side]; } } [spoiler=GuiHandler.java] package com.mymod; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == Gui.GUI_ID) { System.out.print("create gui.\n"); return new Gui(); } return null; } } [spoiler=Gui.java] package com.mymod; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; public class Gui extends GuiScreen { public static final int GUI_ID = 20; public Gui() { System.out.print("gui constructor.\n"); } @Override public void initGui() { buttonList.clear(); buttonList.add(new GuiButton(0, 100, 100, 60, 60, "Button")); } @Override public boolean doesGuiPauseGame() { return false; } @Override public void drawScreen(int i, int j, float f) { drawDefaultBackground(); super.drawScreen(i, j, f); System.out.print("drawing gui.\n"); } @Override public void actionPerformed(GuiButton button) { System.out.print("button clicked.\n"); } }
×
×
  • Create New...

Important Information

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