mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-17 02:55:19 +00:00
Code refactoring
This commit is contained in:
1 parent
e24a94f0ba
commit
f3d3a0a2df
11 files changed
+270
-546
No files matched your search
@@ -12,15 +12,27 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ContainerEffectJar extends effectContainer {
|
||||
public class ContainerEffectJar extends Container {
|
||||
|
||||
public TileEntityEffectJar jar;
|
||||
|
||||
public int lastBeeHealth = 0;
|
||||
public int speciesColour = 0xffffff;
|
||||
|
||||
TileEntityEffectJar jar;
|
||||
public ContainerEffectJar(TileEntityEffectJar tileEntityEffectJar, EntityPlayer player) {
|
||||
super(tileEntityEffectJar, player);
|
||||
jar = (TileEntityEffectJar) inventory;
|
||||
this.jar = tileEntityEffectJar;
|
||||
this.addSlotToContainer(
|
||||
new SlotCustomItems(this.jar, 0, 80, 22, GameRegistry.findItemStack("Forestry", "beeDroneGE", 1)));
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 74 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 132));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,4 +75,29 @@ public class ContainerEffectJar extends effectContainer {
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return this.jar.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
|
||||
Slot itemSlot = this.getSlot(slot);
|
||||
boolean clearSlot = false;
|
||||
|
||||
if (itemSlot != null && itemSlot.getHasStack()) {
|
||||
ItemStack srcStack = itemSlot.getStack();
|
||||
if (slot == 0 && srcStack != null) {
|
||||
clearSlot = this.mergeItemStack(srcStack, 1, 36 + 1, false);
|
||||
} else {
|
||||
if (this.getSlot(0).isItemValid(srcStack)) {
|
||||
clearSlot = this.mergeItemStack(srcStack, 0, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (clearSlot) {
|
||||
itemSlot.putStack(null);
|
||||
}
|
||||
itemSlot.onSlotChanged();
|
||||
player.inventory.markDirty();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,16 @@ package magicbees.client.gui;
|
||||
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
|
||||
public class ContainerEffectRing extends effectContainer {
|
||||
public class ContainerEffectRing extends ContainerItemInventory<InventoryBeeRing> {
|
||||
|
||||
public ContainerEffectRing(InventoryBeeRing IBR, EntityPlayer player) {
|
||||
super(IBR, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
public ContainerEffectRing(InventoryBeeRing inventory, InventoryPlayer playerInventory) {
|
||||
super(inventory, playerInventory, 8, 74);
|
||||
addSlotToContainer(
|
||||
new SlotCustomItems(inventory, 0, 80, 22, GameRegistry.findItemStack("Forestry", "beeDroneGE", 1)));
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,24 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GUIEffectJar extends effectGui {
|
||||
public class GUIEffectJar extends GuiContainer {
|
||||
|
||||
public static final String BACKGROUND_FILE = "jarScreen.png";
|
||||
public static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(
|
||||
CommonProxy.DOMAIN,
|
||||
CommonProxy.GUI_TEXTURE + BACKGROUND_FILE);
|
||||
CommonProxy.GUI_TEXTURE + "jarScreen.png");
|
||||
|
||||
private static final int WIDTH = 176;
|
||||
private static final int HEIGHT = 156;
|
||||
|
||||
private static final int BAR_DEST_X = 117;
|
||||
private static final int BAR_DEST_Y = 10;
|
||||
|
||||
private static final int BAR_SRC_X = 176;
|
||||
private static final int BAR_SRC_Y = 0;
|
||||
|
||||
private static final int BAR_WIDTH = 10;
|
||||
private static final int BAR_HEIGHT = 40;
|
||||
|
||||
public GUIEffectJar(TileEntityEffectJar jar, EntityPlayer player) {
|
||||
super(new ContainerEffectJar(jar, player));
|
||||
@@ -24,6 +34,11 @@ public class GUIEffectJar extends effectGui {
|
||||
this.ySize = HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||
fontRendererObj.drawString("Inventory", 9, 63, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
|
||||
GL11.glColor4f(1f, 1f, 1f, 1f);
|
||||
@@ -32,7 +47,7 @@ public class GUIEffectJar extends effectGui {
|
||||
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
TileEntityEffectJar jar = (TileEntityEffectJar) ((ContainerEffectJar) this.inventorySlots).inventory;
|
||||
TileEntityEffectJar jar = ((ContainerEffectJar) this.inventorySlots).jar;
|
||||
float r = ((jar.currentBeeColour >> 16) & 255) / 255f;
|
||||
float g = ((jar.currentBeeColour >> 8) & 255) / 255f;
|
||||
float b = (jar.currentBeeColour & 255) / 255f;
|
||||
|
||||
@@ -1,50 +1,57 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import magicbees.item.ItemBeeRing;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import magicbees.main.CommonProxy;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GUIEffectRing extends effectGui {
|
||||
import forestry.core.gui.GuiForestry;
|
||||
|
||||
public class GUIEffectRing extends GuiForestry<ContainerEffectRing, IInventory> {
|
||||
|
||||
public static final String BACKGROUND_FILE = "ringScreen.png";
|
||||
public static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(
|
||||
CommonProxy.DOMAIN,
|
||||
CommonProxy.GUI_TEXTURE + BACKGROUND_FILE);
|
||||
|
||||
private static final int BAR_DEST_X = 117;
|
||||
private static final int BAR_DEST_Y = 10;
|
||||
|
||||
public GUIEffectRing(ItemStack itemStack, EntityPlayer player) {
|
||||
super(
|
||||
new ContainerEffectRing(
|
||||
ItemBeeRing.getInventory(player, itemStack, player.inventory.currentItem, false),
|
||||
player));
|
||||
this.xSize = WIDTH;
|
||||
this.ySize = HEIGHT;
|
||||
private static final int BAR_SRC_X = 176;
|
||||
private static final int BAR_SRC_Y = 0;
|
||||
|
||||
private static final int BAR_WIDTH = 10;
|
||||
private static final int BAR_HEIGHT = 40;
|
||||
|
||||
private final InventoryBeeRing inventoryBeeRing;
|
||||
|
||||
protected GUIEffectRing(InventoryBeeRing inventory, InventoryPlayer playerInventory) {
|
||||
super(BACKGROUND_LOCATION, new ContainerEffectRing(inventory, playerInventory), inventory);
|
||||
this.inventoryBeeRing = inventory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
GL11.glColor4f(1f, 1f, 1f, 1f);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_SRC_ALPHA);
|
||||
this.mc.getTextureManager().bindTexture(BACKGROUND_LOCATION);
|
||||
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
InventoryBeeRing IBR = (InventoryBeeRing) ((ContainerEffectRing) this.inventorySlots).inventory;
|
||||
float r = ((IBR.currentBeeColour >> 16) & 255) / 255f;
|
||||
float g = ((IBR.currentBeeColour >> 8) & 255) / 255f;
|
||||
float b = (IBR.currentBeeColour & 255) / 255f;
|
||||
int currentBeeColour = this.inventoryBeeRing.getCurrentBeeColour();
|
||||
float r = ((currentBeeColour >> 16) & 255) / 255f;
|
||||
float g = ((currentBeeColour >> 8) & 255) / 255f;
|
||||
float b = (currentBeeColour & 255) / 255f;
|
||||
|
||||
GL11.glColor3f(r, g, b);
|
||||
|
||||
int value = BAR_HEIGHT - (IBR.currentBeeHealth * BAR_HEIGHT) / 100;
|
||||
int value = BAR_HEIGHT - (this.inventoryBeeRing.getCurrentBeeHealth() * BAR_HEIGHT) / 100;
|
||||
this.drawTexturedModalRect(
|
||||
this.guiLeft + BAR_DEST_X,
|
||||
this.guiTop + value + BAR_DEST_Y,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import magicbees.item.ItemBeeRing;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import magicbees.tileentity.TileEntityEffectJar;
|
||||
import magicbees.tileentity.TileEntityMagicApiary;
|
||||
|
||||
@@ -21,9 +21,7 @@ public class GUIHandler implements IGuiHandler {
|
||||
TileEntityMagicApiary tileEntityThaumicApiary = (TileEntityMagicApiary) world.getTileEntity(x, y, z);
|
||||
value = new ContainerMagicApiary(player.inventory, tileEntityThaumicApiary);
|
||||
} else if (ID == UIScreens.EFFECT_RING.ordinal()) {
|
||||
value = new ContainerEffectRing(
|
||||
ItemBeeRing.getInventory(player, player.getHeldItem(), player.inventory.currentItem, false),
|
||||
player);
|
||||
value = new ContainerEffectRing(new InventoryBeeRing(player.getHeldItem(), player), player.inventory);
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -37,7 +35,7 @@ public class GUIHandler implements IGuiHandler {
|
||||
TileEntityMagicApiary tileEntityThaumicApiary = (TileEntityMagicApiary) world.getTileEntity(x, y, z);
|
||||
return new GuiMagicApiary(player.inventory, tileEntityThaumicApiary);
|
||||
} else if (ID == UIScreens.EFFECT_RING.ordinal()) {
|
||||
return new GUIEffectRing(player.getHeldItem(), player);
|
||||
return new GUIEffectRing(new InventoryBeeRing(player.getHeldItem(), player), player.inventory);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
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 abstract class effectContainer extends Container {
|
||||
|
||||
public IInventory inventory;
|
||||
|
||||
public effectContainer(IInventory inventory, EntityPlayer player) {
|
||||
this.inventory = inventory;
|
||||
this.addSlotToContainer(
|
||||
new SlotCustomItems(this.inventory, 0, 80, 22, GameRegistry.findItemStack("Forestry", "beeDroneGE", 1)));
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 74 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 132));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
|
||||
Slot itemSlot = this.getSlot(slot);
|
||||
boolean clearSlot = false;
|
||||
|
||||
if (itemSlot != null && itemSlot.getHasStack()) {
|
||||
ItemStack srcStack = itemSlot.getStack();
|
||||
if (slot == 0 && srcStack != null) {
|
||||
clearSlot = this.mergeItemStack(srcStack, 1, 36 + 1, false);
|
||||
} else {
|
||||
if (this.getSlot(0).isItemValid(srcStack)) {
|
||||
clearSlot = this.mergeItemStack(srcStack, 0, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (clearSlot) {
|
||||
itemSlot.putStack(null);
|
||||
}
|
||||
itemSlot.onSlotChanged();
|
||||
player.inventory.markDirty();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class effectGui extends GuiContainer {
|
||||
|
||||
protected static final int WIDTH = 176;
|
||||
protected static final int HEIGHT = 156;
|
||||
|
||||
protected static final int BAR_DEST_X = 117;
|
||||
protected static final int BAR_DEST_Y = 10;
|
||||
|
||||
protected static final int BAR_SRC_X = 176;
|
||||
protected static final int BAR_SRC_Y = 0;
|
||||
|
||||
protected static final int BAR_WIDTH = 10;
|
||||
protected static final int BAR_HEIGHT = 40;
|
||||
|
||||
public effectGui(Container cont) {
|
||||
super(cont);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||
fontRendererObj.drawString("Inventory", 9, 63, 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user