Своя печка

Версия Minecraft
1.7.10
53
1
Всем привет ребята!
Подскажите как сделать печку и свой GUI для этой печки!
 

timaxa007

Модератор
5,831
409
672
Если ты про урок от _Bedrock_Miner_, то вроде там основы расписаны (хотя я в них вникать не стал).
Изучаешь как делать GuiHandler, а код можно брать от ванильной печи.
 
53
1
timaxa007 написал(а):
Если ты про урок от _Bedrock_Miner_, то вроде там основы расписаны (хотя я в них вникать не стал).
Изучаешь как делать GuiHandler, а код можно брать от ванильной печи.

Что точно я должен разобрать чтоб зделать печку простую какие классы мне понадобятся?
 
53
1
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю

всё понял спасибо


vites написал(а):
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю

всё понял спасибо

аааааааааа  не чего не понял что куда кидать!
 
1,470
19
189
vites написал(а):
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю

всё понял спасибо


vites написал(а):
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю

всё понял спасибо

аааааааааа  не чего не понял что куда кидать!


Это не смешно
 
53
1
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю
Я кидал, переделовал но нечего не смог, не могу зарегистрировать печку или там тайлы!
 
[img=250x250]http://i.imgur.com/forcJsL.png[/img]

Вам нужно создать GuiHundler
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;
import com.Savage.redpw.Main;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHundler implements IGuiHandler {

 @Override
 public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
 switch(ID)
 {
 case 0: return new ChemaConteiner(player.inventory, (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z)));
 default: return null;
 }
 }

 @Override
 public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
 switch(ID)
 {
 case 0: return new GiuChema(new ChemaConteiner(player.inventory, (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z))), (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z)));
 default: return null;
 }
 }

}



Потом сам gui аля картинка сзади и тд...
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class GiuChema extends GuiContainer{
 
 public BlinkingTileEntity tile;
 public static final ResourceLocation F_GUI = new ResourceLocation("redpw:textures/gui/Chemer.png");
 public GiuChema(Container inventorySlotsIn, BlinkingTileEntity tile) {
 super(inventorySlotsIn);
 // TODO Auto-generated constructor stub
 this.tile = tile;
 }

 @Override
 protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
 mc.renderEngine.bindTexture(F_GUI);
 int x = (this.width - this.xSize) / 2;
 int y = (this.height - this.ySize) / 2;
 drawTexturedModalRect(x, y, 0, 0, xSize, ySize);//Menu
}


И создать сам класс со слотами:
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ChemaConteiner extends Container
{
  public ChemaConteiner(IInventory playerInv, BlinkingTileEntity barrel) {
          int i = -18;
  int j;
  int k;
         
  addSlotToContainer(new Slot(barrel.inventory, 1, 8, 61));
  addSlotToContainer(new Slot(barrel.inventory, 2, 80, 33));//Инвентарь, id слота, X, Y

  for (j = 0; j < 3; ++j){
      for (k = 0; k < 9; ++k) {
          this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 102 + j * 18 + i));//Слоты инвентаря 
      }
  }

  for (j = 0; j < 9; ++j) {
      this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 160 + i));//Слоты инвентаря (нижния полоска)
  }
   //
  }
  

@Override
  public boolean canInteractWith(EntityPlayer playerIn) {
          return true;
  }
 
  public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  ItemStack itemstack = null;
  Slot slot = (Slot)this.inventorySlots.get(index);

  if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (index < 27) {
          if (!this.mergeItemStack(itemstack1, 27, this.inventorySlots.size(), true)) {
              return null;
          }
      }
      else if(!this.mergeItemStack(itemstack1, 0, 27, false)) {
          return null;
      }

      if (itemstack1.stackSize == 0) {
          slot.putStack((ItemStack)null);
      }
      else {
          slot.onSlotChanged();
      }
  }

  return itemstack;
}
}

И в TileEntity засунуть:
Код:
package com.Savage.redpw;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

public class BlinkingTileEntity extends TileEntity implements ITickable
{
 public InventoryBasic inventory;
 
 
 public BlinkingTileEntity()
 {
 inventory = new InventoryBasic("Namer", true, 15);
 }
 
 @Override
 public void writeToNBT(NBTTagCompound compound) 
 {
 super.writeToNBT(compound);
 NBTTagList list = new NBTTagList();
 
 for(int i = 0; i < inventory.getSizeInventory(); i++)
 {
 if(inventory.getStackInSlot(i) != null)
 {
 NBTTagCompound component = new NBTTagCompound();
 component.setByte("Slot", (byte)i);
 inventory.getStackInSlot(i).writeToNBT(component);
 list.appendTag(component);
 }
 }
 compound.setTag("ItemStaks", list);
 }
 
 @Override
 public void readFromNBT(NBTTagCompound compound) 
 {
 super.readFromNBT(compound);
 NBTTagList ls = compound.getTagList("ItemStaks", 10);
 this.inventory = new InventoryBasic("Namer", false, 15); 
 for(int i = 0; i < ls.tagCount(); i++)
 {
 NBTTagCompound tag = ls.getCompoundTagAt(i);
 byte b = tag.getByte("Slot");
 if(b >= 0 && b < inventory.getSizeInventory())
 {
 inventory.setInventorySlotContents(b, ItemStack.loadItemStackFromNBT(tag));
 }
 }
 }
 
 
 @Override
 public void update() 
 {
}

Ну как то так...



Открывается вот так:
Код:
playerIn.openGui(Main.INSTANCE, 0, worldIn,  pos.getX(), pos.getY(), pos.getZ());

0 - ID из GuiHundler
Main.INSTANCE - 

    //В главный клас (у меня это Main)
    @Instance(MODID)
    public static Main INSTANCE;
playerIn это EntityPlayer
 
53
1
Jack_Savage написал(а):
[img=250x250]http://i.imgur.com/forcJsL.png[/img]

Вам нужно создать GuiHundler
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;
import com.Savage.redpw.Main;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHundler implements IGuiHandler {

 @Override
 public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
 switch(ID)
 {
 case 0: return new ChemaConteiner(player.inventory, (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z)));
 default: return null;
 }
 }

 @Override
 public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
 switch(ID)
 {
 case 0: return new GiuChema(new ChemaConteiner(player.inventory, (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z))), (BlinkingTileEntity) world.getTileEntity(new BlockPos(x, y, z)));
 default: return null;
 }
 }

}



Потом сам gui аля картинка сзади и тд...
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class GiuChema extends GuiContainer{
 
 public BlinkingTileEntity tile;
 public static final ResourceLocation F_GUI = new ResourceLocation("redpw:textures/gui/Chemer.png");
 public GiuChema(Container inventorySlotsIn, BlinkingTileEntity tile) {
 super(inventorySlotsIn);
 // TODO Auto-generated constructor stub
 this.tile = tile;
 }

 @Override
 protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
 mc.renderEngine.bindTexture(F_GUI);
 int x = (this.width - this.xSize) / 2;
 int y = (this.height - this.ySize) / 2;
 drawTexturedModalRect(x, y, 0, 0, xSize, ySize);//Menu
}


И создать сам класс со слотами:
Код:
package com.Savage.redpw.gui;

import com.Savage.redpw.BlinkingTileEntity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ChemaConteiner extends Container
{
  public ChemaConteiner(IInventory playerInv, BlinkingTileEntity barrel) {
          int i = -18;
  int j;
  int k;
         
  addSlotToContainer(new Slot(barrel.inventory, 1, 8, 61));
  addSlotToContainer(new Slot(barrel.inventory, 2, 80, 33));//Инвентарь, id слота, X, Y

  for (j = 0; j < 3; ++j){
      for (k = 0; k < 9; ++k) {
          this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 102 + j * 18 + i));//Слоты инвентаря 
      }
  }

  for (j = 0; j < 9; ++j) {
      this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 160 + i));//Слоты инвентаря (нижния полоска)
  }
   //
  }
  

@Override
  public boolean canInteractWith(EntityPlayer playerIn) {
          return true;
  }
 
  public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  ItemStack itemstack = null;
  Slot slot = (Slot)this.inventorySlots.get(index);

  if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (index < 27) {
          if (!this.mergeItemStack(itemstack1, 27, this.inventorySlots.size(), true)) {
              return null;
          }
      }
      else if(!this.mergeItemStack(itemstack1, 0, 27, false)) {
          return null;
      }

      if (itemstack1.stackSize == 0) {
          slot.putStack((ItemStack)null);
      }
      else {
          slot.onSlotChanged();
      }
  }

  return itemstack;
}
}

И в TileEntity засунуть:
Код:
package com.Savage.redpw;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

public class BlinkingTileEntity extends TileEntity implements ITickable
{
 public InventoryBasic inventory;
 
 
 public BlinkingTileEntity()
 {
 inventory = new InventoryBasic("Namer", true, 15);
 }
 
 @Override
 public void writeToNBT(NBTTagCompound compound) 
 {
 super.writeToNBT(compound);
 NBTTagList list = new NBTTagList();
 
 for(int i = 0; i < inventory.getSizeInventory(); i++)
 {
 if(inventory.getStackInSlot(i) != null)
 {
 NBTTagCompound component = new NBTTagCompound();
 component.setByte("Slot", (byte)i);
 inventory.getStackInSlot(i).writeToNBT(component);
 list.appendTag(component);
 }
 }
 compound.setTag("ItemStaks", list);
 }
 
 @Override
 public void readFromNBT(NBTTagCompound compound) 
 {
 super.readFromNBT(compound);
 NBTTagList ls = compound.getTagList("ItemStaks", 10);
 this.inventory = new InventoryBasic("Namer", false, 15); 
 for(int i = 0; i < ls.tagCount(); i++)
 {
 NBTTagCompound tag = ls.getCompoundTagAt(i);
 byte b = tag.getByte("Slot");
 if(b >= 0 && b < inventory.getSizeInventory())
 {
 inventory.setInventorySlotContents(b, ItemStack.loadItemStackFromNBT(tag));
 }
 }
 }
 
 
 @Override
 public void update() 
 {
}

Ну как то так...



Открывается вот так:
Код:
playerIn.openGui(Main.INSTANCE, 0, worldIn,  pos.getX(), pos.getY(), pos.getZ());

0 - ID из GuiHundler
Main.INSTANCE - 

    //В главный клас (у меня это Main)
    @Instance(MODID)
    public static Main INSTANCE;
playerIn это EntityPlayer



Спасибо большое, чуть позже кину в свои мод!


vites написал(а):
Jack_Savage написал(а):
[img=250x500]http://i.imgur.com/GEhJ9w3.png[/img]
Вот в этих "папках" можно найти.
Там стандартный код майна как я понимаю
Я кидал, переделовал но нечего не смог, не могу зарегистрировать печку или там тайлы!
На счёт этого
Код:
playerIn.openGui(Main.INSTANCE, 0, worldIn,  pos.getX(), pos.getY(), pos.getZ());

0 - ID из GuiHundler
Main.INSTANCE - 

    //В главный клас (у меня это Main)
    @Instance(MODID)
    public static Main INSTANCE;
playerIn это EntityPlayer
я не понял
 
Мой тебе совет: сначала сделай простой мод, добавляющий хотя бы блок, а потом уже переходи к более сложным. Печка - никак не для новичка. И еще нужно знать джаву не на базовом уровне, а на более углубленном.
 
53
1
GreenBudgie написал(а):
Мой тебе совет: сначала сделай простой мод, добавляющий хотя бы блок, а потом уже переходи к более сложным. Печка - никак не для новичка. И еще нужно знать джаву не на базовом уровне, а на более углубленном.

Я делал простой мод так что я хочу чего то большего чем блок руды, генератор руды!
 
Сверху