- 19
- 0
Во время открытия инвентаря блока у него есть слоты контейнера и все функции тайла работают, но есть проблема почему-то нету самой гуи на заднем фоне:
Gui:
GuiHandler:
Container:
TileEntity:
Регистрация GuiHandler
Открытие Gui
Буду благодарен, если поможите, просто впервые пишу gui, так что ещё не разобрался с ним

Gui:
Gui:
public class GuiSolarPanel
{
public static class GuiOtherworldSP extends GuiContainer
{
private static final ResourceLocation texture = new ResourceLocation(Industry.domain, "textures/gui/panel/GuiOtherworld.png");
private TileEntitySolarPanel tile;
public GuiOtherworldSP(InventoryPlayer player, TileEntitySolarPanel entity) {
super(new ContainerSolarPanel(player, entity));
this.allowUserInput = false;
this.tile = entity;
this.xSize = 187;
this.ySize = 191;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1F, 1F, 1F, 1F);
try{
Minecraft.getMinecraft().getResourceManager().getResource(texture);
} catch(IOException exception) {
System.out.println("Failed to load texture!");
exception.printStackTrace();
}
int i =(this.width - this.xSize) / 2;
int k = (this.height - this.ySize) / 2;
if(this.tile.storage > 0) {
int l = this.tile.gaugeEnergyScaled(24);
this.drawTexturedModalRect(i + 35, k + 54, 187, 5, l + 0, 54);
}
}
}
}
GuiHandler:
GuiHandler:
public class GuiHandler implements IGuiHandler
{
public GuiHandler() {}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if(tile != null) {
if(tile instanceof TileEntitySolarPanel) {
return ((TileEntitySolarPanel) tile).getGuiContainer(player.inventory);
} else {
return null;
}
} else {
return null;
}
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
System.out.println("OpenGui");
if(tile != null) {
if(tile instanceof TileEntitySolarPanel) {
return new GuiSolarPanel.GuiOtherworldSP(player.inventory, (TileEntitySolarPanel) tile);
} else {
return null;
}
} else {
return null;
}
}
}
Container:
Container:
public class ContainerSolarPanel extends Container
{
private TileEntitySolarPanel tile;
private int storage = 0;
public ContainerSolarPanel(InventoryPlayer player, TileEntitySolarPanel entity) {
this.tile = entity;
for(int i = 0; i < 3; ++i) {
this.addSlotToContainer(new Slot(this.tile, i, 135, 29 + i * 18));
}
//Vanilla Inventory
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(player, j + 9 + i * 9, 14 + j * 18, 109 + i * 18));
}
}
for(int i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(player, i, 14 + i * 18, 167));
}
}
@Override
public void addCraftingToCrafters(ICrafting iCrafting) {
super.addCraftingToCrafters(iCrafting);
iCrafting.sendProgressBarUpdate(this, 0, this.tile.storage & '\uffff');
iCrafting.sendProgressBarUpdate(this, 1, this.tile.storage >>> 16);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for(int i = 0; i < this.crafters.size(); ++i) {
ICrafting iCrafting =(ICrafting) this.crafters.get(i);
iCrafting.sendProgressBarUpdate(this, 0, this.tile.storage & '\uffff');
iCrafting.sendProgressBarUpdate(this, 1, this.tile.storage >>> 16);
}
this.storage = this.tile.storage;
}
@Override
public void updateProgressBar(int par1, int par2) {
if(par1 == 1) {
this.tile.storage = this.tile.storage & - 10000 | par2;
}
if(par1 == 2) {
this.tile.storage = this.tile.storage & '\uffff' | par2 << 16;
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int par1) {
int slot = par1;
ItemStack stack = null;
Slot slotObject = (Slot)this.inventorySlots.get(par1);
if (slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot >= 0 && slot <= 3) {
if (!this.mergeItemStack(stackInSlot, 4, 40, true)) {
return null;
}
} else if (slot >= 4 && slot < 31) {
if (!this.mergeItemStack(stackInSlot, 0, 4, false) && !this.mergeItemStack(stackInSlot, 31, 40, false)) {
return null;
}
} else if (slot >= 31 && slot < 39) {
if (!this.mergeItemStack(stackInSlot, 0, 30, false)) {
return null;
}
} else if (!this.mergeItemStack(stackInSlot, 0, 30, false)) {
return null;
}
if (stackInSlot.stackSize == 0) {
slotObject.putStack((ItemStack)null);
} else {
slotObject.onSlotChanged();
}
if (stack.stackSize == stackInSlot.stackSize) {
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return this.tile.isUseableByPlayer(player);
}
}
TileEntity:
TileEntity:
public class TileEntitySolarPanel extends TileEntityBase implements IEnergyTile, IWrenchableUpgrade, IEnergySource, INetworkDataProvider, INetworkUpdateListener, IInventory
{
public static Random randomizer = new Random();
public ItemStack[] chargeSlot;
public String panelName;
public int maxOutput;
public int maxStorage;
public int storage;
public int ticker;
public int generating;
public int genDay;
public int genNight;
public int fuel;
private int lastX;
private int lastY;
private int lastZ;
private int solarType;
private int machineTire;
private short facing = 2;
public boolean loaded = false;
public boolean initialized;
public boolean sunIsUp;
public boolean skyIsVisible;
private boolean noSunWorld;
private boolean wetBiome;
public boolean addedToEnergyNet;
private boolean created = false;
private static List<String> fields = Arrays.asList();
public TileEntitySolarPanel(String name, int genDay1, int genNight1, int maxOutput1, int maxStorage1) {
this.ticker = randomizer.nextInt(this.tickRate());
this.solarType = 1;
this.genDay = genDay1;
this.genNight = genNight1;
this.storage = 0;
this.panelName = name;
this.sunIsUp = false;
this.skyIsVisible = false;
this.maxStorage = maxStorage1;
this.initialized = false;
this.maxOutput = maxOutput1;
this.lastX = this.xCoord;
this.lastY = this.yCoord;
this.lastZ = this.zCoord;
this.chargeSlot = new ItemStack[3];
this.machineTire = Integer.MAX_VALUE;
}
public void validate() {
super.validate();
if (!this.isInvalid() && this.worldObj.blockExists(this.xCoord, this.yCoord, this.zCoord)) {
this.onLoaded();
}
}
public void invalidate() {
if (this.loaded) {
this.onUnloaded();
}
super.invalidate();
}
public void onLoaded() {
if (!this.worldObj.isRemote) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
}
this.loaded = true;
}
public void onChunkUnload() {
if (this.loaded) {
this.onUnloaded();
}
super.onChunkUnload();
}
public void onUnloaded() {
if (!this.worldObj.isRemote && this.addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false;
}
this.loaded = false;
}
public void intialize() {
this.wetBiome = this.worldObj.getWorldChunkManager().getBiomeGenAt(this.xCoord, this.zCoord).getIntRainfall() > 0;
this.noSunWorld = this.worldObj.provider.hasNoSky;
this.updateVisibility();
this.initialized = true;
if (!this.addedToEnergyNet) {
this.onLoaded();
}
}
public void updateEntity() {
super.updateEntity();
if (!this.initialized && this.worldObj != null) {
this.intialize();
}
if (!this.worldObj.isRemote) {
if (this.lastX != this.xCoord || this.lastZ != this.zCoord || this.lastY != this.yCoord) {
this.lastX = this.xCoord;
this.lastY = this.yCoord;
this.lastZ = this.zCoord;
this.onUnloaded();
this.intialize();
}
this.gainFuel();
if (this.generating > 0) {
if (this.storage + this.generating <= this.maxStorage) {
this.storage += this.generating;
} else {
this.storage = this.maxStorage;
}
}
boolean needInvUpdate = false;
double sentPacket = 0.0;
for(int i = 0; i < this.chargeSlot.length; ++i) {
if (this.chargeSlot[i] != null && this.chargeSlot[i].getItem() instanceof IElectricItem && this.storage > 0) {
sentPacket = ElectricItem.manager.charge(this.chargeSlot[i], (double)this.storage, Integer.MAX_VALUE, false, false);
if (sentPacket > 0.0) {
needInvUpdate = true;
}
this.storage = (int)((double)this.storage - sentPacket);
}
}
if (needInvUpdate) {
super.markDirty();
}
}
}
public int gainFuel() {
if (this.ticker++ % this.tickRate() == 0) {
this.updateVisibility();
}
if (this.sunIsUp && this.skyIsVisible) {
this.generating = 0 + this.genDay;
return this.generating;
} else if (this.skyIsVisible) {
this.generating = 0 + this.genNight;
return this.generating;
} else {
this.generating = 0;
return this.generating;
}
}
public void updateVisibility() {
Boolean rainWeather = this.wetBiome && (this.worldObj.isRaining() || this.worldObj.isThundering());
if (this.worldObj.isDaytime() && !rainWeather) {
this.sunIsUp = true;
} else {
this.sunIsUp = false;
}
if (this.worldObj.canBlockSeeTheSky(this.xCoord, this.yCoord + 1, this.zCoord) && !this.noSunWorld) {
this.skyIsVisible = true;
} else {
this.skyIsVisible = false;
}
}
public int gaugeEnergyScaled(int i) {
return this.storage * i / this.maxStorage;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.storage = nbttagcompound.getInteger("storage");
this.lastX = nbttagcompound.getInteger("lastX");
this.lastY = nbttagcompound.getInteger("lastY");
this.lastZ = nbttagcompound.getInteger("lastZ");
this.chargeSlot = new ItemStack[this.getSizeInventory()];
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 255;
if (j >= 0 && j < this.chargeSlot.length) {
this.chargeSlot[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
nbttagcompound.setInteger("storage", this.storage);
nbttagcompound.setInteger("lastX", this.lastX);
nbttagcompound.setInteger("lastY", this.lastY);
nbttagcompound.setInteger("lastZ", this.lastZ);
for(int i = 0; i < this.chargeSlot.length; ++i) {
if (this.chargeSlot[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.chargeSlot[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
}
public int tickRate() {
return 128;
}
public short getFacing() {
return this.facing;
}
public void setFacing(short facing) {
this.facing = facing;
}
public boolean wrenchCanSetFacing(EntityPlayer entityplayer, int i) {
return false;
}
public boolean wrenchCanRemove(EntityPlayer entityplayer) {
return true;
}
public float getWrenchDropRate() {
return 1.0F;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
}
public void onNetworkUpdate(String field) {}
public List<String> getNetworkedFields() {
return fields;
}
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
return true;
}
public double getOfferedEnergy() {
return (double)Math.min(this.maxOutput, this.storage);
}
public void drawEnergy(double amount) {
this.storage = (int)((double)this.storage - amount);
}
public int getSourceTier() {
return this.machineTire;
}
@Override
public int getSizeInventory() {
return this.chargeSlot.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return this.chargeSlot[slot];
}
@Override
public ItemStack decrStackSize(int slot1, int slot2) {
if (this.chargeSlot[slot1] != null)
{
ItemStack itemstack;
if (this.chargeSlot[slot1].stackSize <= slot2)
{
itemstack = this.chargeSlot[slot1];
this.chargeSlot[slot1] = null;
return itemstack;
}
else
{
itemstack = this.chargeSlot[slot1].splitStack(slot2);
if (this.chargeSlot[slot1].stackSize == 0)
{
this.chargeSlot[slot1] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (this.chargeSlot[slot] != null)
{
ItemStack itemstack = this.chargeSlot[slot];
this.chargeSlot[slot] = null;
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
this.chargeSlot[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
{
itemStack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public String getInventoryName() {
return "gui." + panelName;
}
public Container getGuiContainer(InventoryPlayer inventoryplayer) {
return new ContainerSolarPanel(inventoryplayer, this);
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@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.5D, (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;
}
}
Регистрация GuiHandler
Register GuiHandler:
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
Открытие Gui
Open Gui:
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
return false;
} else if (world.isRemote) {
return true;
} else {
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity != null) {
player.openGui(Industry.instance, 1, world, x, y, z);
}
return true;
}
}
Буду благодарен, если поможите, просто впервые пишу gui, так что ещё не разобрался с ним