mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-13 00:37:51 +00:00
Fully Fleshed out Functionality and GUI. Having some small issues with the paritcleFX, but not huge deal right now. Would be nice to have, but crashes make people even sadder.
This commit is contained in:
1 parent
e5cea4e3dd
commit
729908b1b0
6 files changed
+542
-82
No files matched your search
@@ -3,26 +3,38 @@ package magicbees.client.gui;
|
||||
import magicbees.item.ItemBeeRing;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import magicbees.main.CommonProxy;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GUIEffectRing extends GuiContainer {
|
||||
|
||||
|
||||
public static final String BACKGROUND_FILE = "jarScreen.png";
|
||||
public static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(
|
||||
CommonProxy.DOMAIN,
|
||||
CommonProxy.GUI_TEXTURE + "jarScreen.png");
|
||||
CommonProxy.DOMAIN,
|
||||
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 GUIEffectRing(ItemStack itemStack, EntityPlayer player) {
|
||||
super(new ContainerEffectRing((InventoryBeeRing) ItemBeeRing.getInventory(player, itemStack), player));
|
||||
super(
|
||||
new ContainerEffectRing(
|
||||
ItemBeeRing.getInventory(player, itemStack, player.inventory.currentItem, false),
|
||||
player));
|
||||
this.xSize = WIDTH;
|
||||
this.ySize = HEIGHT;
|
||||
}
|
||||
@@ -39,5 +51,21 @@ public class GUIEffectRing extends GuiContainer {
|
||||
this.mc.getTextureManager().bindTexture(BACKGROUND_LOCATION);
|
||||
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
InventoryBeeRing IBR = ((ContainerEffectRing) this.inventorySlots).IBR;
|
||||
float r = ((IBR.currentBeeColour >> 16) & 255) / 255f;
|
||||
float g = ((IBR.currentBeeColour >> 8) & 255) / 255f;
|
||||
float b = (IBR.currentBeeColour & 255) / 255f;
|
||||
|
||||
GL11.glColor3f(r, g, b);
|
||||
|
||||
int value = BAR_HEIGHT - (IBR.currentBeeHealth * BAR_HEIGHT) / 100;
|
||||
this.drawTexturedModalRect(
|
||||
this.guiLeft + BAR_DEST_X,
|
||||
this.guiTop + value + BAR_DEST_Y,
|
||||
BAR_SRC_X,
|
||||
BAR_SRC_Y,
|
||||
BAR_WIDTH,
|
||||
BAR_HEIGHT - value);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import magicbees.item.ItemBeeRing;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import magicbees.tileentity.TileEntityEffectJar;
|
||||
import magicbees.tileentity.TileEntityMagicApiary;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import scala.swing.Applet;
|
||||
|
||||
public class GUIHandler implements IGuiHandler {
|
||||
|
||||
@@ -24,7 +21,9 @@ 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((InventoryBeeRing) ItemBeeRing.getInventory(player, player.getHeldItem()),player);
|
||||
value = new ContainerEffectRing(
|
||||
ItemBeeRing.getInventory(player, player.getHeldItem(), player.inventory.currentItem, false),
|
||||
player);
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -38,7 +37,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(player.getHeldItem(), player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
package magicbees.item;
|
||||
|
||||
import magicbees.client.gui.UIScreens;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.MagicBees;
|
||||
import magicbees.tileentity.RingHousing;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
@@ -8,19 +23,6 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import magicbees.client.gui.UIScreens;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.MagicBees;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
|
||||
public class ItemBeeRing extends Item implements IBauble {
|
||||
|
||||
@@ -29,8 +31,8 @@ public class ItemBeeRing extends Item implements IBauble {
|
||||
|
||||
private final int DRONE_SLOT = 0;
|
||||
private final int QUEEN_SLOT = 1;
|
||||
public ItemBeeRing()
|
||||
{
|
||||
|
||||
public ItemBeeRing() {
|
||||
super();
|
||||
this.maxStackSize = 1;
|
||||
this.canRepair = false;
|
||||
@@ -40,26 +42,25 @@ public class ItemBeeRing extends Item implements IBauble {
|
||||
GameRegistry.registerItem(this, "beeRing");
|
||||
}
|
||||
|
||||
// Equips item if shift is held and otherwise it opens the GUI
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
|
||||
if (null == itemStack.getTagCompound())
|
||||
{
|
||||
onCreated(itemStack, world, player);
|
||||
}
|
||||
|
||||
if (!world.isRemote) {
|
||||
if(!player.isSneaking())
|
||||
{
|
||||
player.openGui(MagicBees.object, UIScreens.EFFECT_RING.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.isSneaking()) {
|
||||
player.openGui(
|
||||
MagicBees.object,
|
||||
UIScreens.EFFECT_RING.ordinal(),
|
||||
world,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ);
|
||||
} else {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
|
||||
for(int i = 0; i < baubles.getSizeInventory(); ++i) {
|
||||
for (int i = 0; i < baubles.getSizeInventory(); ++i) {
|
||||
if (baubles.getStackInSlot(i) == null && baubles.isItemValidForSlot(i, itemStack)) {
|
||||
baubles.setInventorySlotContents(i, itemStack.copy());
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
this.onEquipped(itemStack, player);
|
||||
break;
|
||||
}
|
||||
@@ -82,18 +83,34 @@ public class ItemBeeRing extends Item implements IBauble {
|
||||
|
||||
@Override
|
||||
public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
|
||||
if (entityLivingBase instanceof EntityPlayer)
|
||||
{
|
||||
if (hasQueen(itemStack, (EntityPlayer) entityLivingBase)) {
|
||||
tickQueen(itemStack);
|
||||
} else if (hasDrone(itemStack, (EntityPlayer) entityLivingBase)) {
|
||||
createQueenFromDrone(itemStack, (EntityPlayer) entityLivingBase);
|
||||
|
||||
// If I'm being honest I'm not sure if this needs to go here, but it works if I put it here.
|
||||
if (!entityLivingBase.worldObj.isRemote) {
|
||||
if (entityLivingBase instanceof EntityPlayer) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles((EntityPlayer) entityLivingBase);
|
||||
int slot = -1;
|
||||
for (int i = 0; i < baubles.getSizeInventory(); i++) {
|
||||
if (baubles.getStackInSlot(i) == itemStack) {
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Logic to run the ring (this logic could be moved out of the item class, but it seems fine here
|
||||
if (slot != -1) {
|
||||
if (hasQueen(itemStack, (EntityPlayer) entityLivingBase, slot)) {
|
||||
tickQueen(itemStack, (EntityPlayer) entityLivingBase, slot);
|
||||
} else if (hasDrone(itemStack, (EntityPlayer) entityLivingBase, slot)) {
|
||||
createQueenFromDrone(itemStack, (EntityPlayer) entityLivingBase, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createQueenFromDrone(ItemStack itemStack, EntityPlayer player) {
|
||||
IInventory IBR = getInventory(player, itemStack);
|
||||
private void createQueenFromDrone(ItemStack itemStack, EntityPlayer player, int slot) {
|
||||
|
||||
InventoryBeeRing IBR = getInventory(player, itemStack, slot, true);
|
||||
ItemStack droneStack = IBR.getStackInSlot(0);
|
||||
if (magicbees.bees.BeeManager.beeRoot.isDrone(droneStack)) {
|
||||
IBee bee = magicbees.bees.BeeManager.beeRoot.getMember(droneStack);
|
||||
@@ -103,27 +120,66 @@ public class ItemBeeRing extends Item implements IBauble {
|
||||
droneStack.stackSize = droneStack.stackSize - 1;
|
||||
IBR.setInventorySlotContents(0, droneStack);
|
||||
}
|
||||
|
||||
ItemStack temp = droneStack.copy();
|
||||
temp.stackSize = 1;
|
||||
IBR.setInventorySlotContents(1, temp);
|
||||
|
||||
int current = bee.getHealth();
|
||||
int max = bee.getMaxHealth();
|
||||
// currentBeeHealth = (current * 100) / max;
|
||||
// currentBeeColour = bee.getGenome().getPrimary().getIconColour(0);
|
||||
IBR.setCurrentBeeHealth((current * 100) / max);
|
||||
IBR.setCurrentBeeColour(bee.getGenome().getPrimary().getIconColour(0));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasDrone(ItemStack itemStack, EntityPlayer player) {
|
||||
return getInventory(player, itemStack).getStackInSlot(DRONE_SLOT) != null;
|
||||
private boolean hasDrone(ItemStack itemStack, EntityPlayer player, int slot) {
|
||||
return getInventory(player, itemStack, slot, true).getStackInSlot(DRONE_SLOT) != null;
|
||||
}
|
||||
|
||||
private void tickQueen(ItemStack itemStack) {
|
||||
private void tickQueen(ItemStack itemStack, EntityPlayer player, int slot) {
|
||||
|
||||
InventoryBeeRing IBR = getInventory(player, itemStack, slot, true);
|
||||
|
||||
IBee queen = magicbees.bees.BeeManager.beeRoot.getMember(IBR.getStackInSlot(QUEEN_SLOT));
|
||||
IBR.setCurrentBeeHealth((queen.getHealth() * 100) / queen.getMaxHealth());
|
||||
IBR.setCurrentBeeColour(queen.getGenome().getPrimary().getIconColour(0));
|
||||
|
||||
RingHousing housingLogic = new RingHousing(player, IBR);
|
||||
|
||||
IBR.setEffectAndInitialize(queen);
|
||||
|
||||
IBR.effectData = queen.doEffect(IBR.effectData, housingLogic);
|
||||
if (player.isDead) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBR.writeEffectNBT();
|
||||
|
||||
// Crashes irregularly for some reason I can't figure out, but this is just the bee effects around you, so it's
|
||||
// not a huge deal. It would be nice to have though
|
||||
// I will get around to it later. (Crash has something to do with entityFX when the player is moving)
|
||||
// if (player.getEntityWorld().getWorldTime() % 5 == 0) {
|
||||
// IBR.effectData = queen.doFX(IBR.effectData, housingLogic);
|
||||
// }
|
||||
|
||||
// run the queen
|
||||
if (IBR.throttle > 550) {
|
||||
IBR.setThrottle(0);
|
||||
queen.age(player.getEntityWorld(), 0.26f);
|
||||
|
||||
if (queen.getHealth() == 0) {
|
||||
IBR.setInventorySlotContents(1, null);
|
||||
IBR.setCurrentBeeHealth(0);
|
||||
IBR.setCurrentBeeColour(0x0ffffff);
|
||||
} else {
|
||||
queen.writeToNBT(IBR.contents[QUEEN_SLOT].stackTagCompound);
|
||||
}
|
||||
} else {
|
||||
IBR.setThrottle(IBR.throttle + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasQueen(ItemStack itemStack, EntityPlayer player) {
|
||||
return getInventory(player, itemStack).getStackInSlot(QUEEN_SLOT) != null;
|
||||
private boolean hasQueen(ItemStack itemStack, EntityPlayer player, int slot) {
|
||||
return getInventory(player, itemStack, slot, true).getStackInSlot(QUEEN_SLOT) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,14 +202,8 @@ public class ItemBeeRing extends Item implements IBauble {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
|
||||
{
|
||||
// if (itemStack.getTagCompound() == null) {
|
||||
// itemStack.setTagCompound(new NBTTagCompound());
|
||||
// }
|
||||
}
|
||||
public static IInventory getInventory(EntityPlayer player, ItemStack itemStack)
|
||||
{
|
||||
return new InventoryBeeRing(itemStack, player);
|
||||
public static InventoryBeeRing getInventory(EntityPlayer player, ItemStack itemStack, int slot,
|
||||
boolean baubleFlag) {
|
||||
return new InventoryBeeRing(itemStack, player, slot, baubleFlag);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,44 @@
|
||||
package magicbees.itemInventories;
|
||||
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.IAlleleBeeEffect;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
|
||||
public class InventoryBeeRing implements IInventory {
|
||||
|
||||
public EntityPlayer player;
|
||||
public ItemStack parent;
|
||||
public ItemStack[] contents;
|
||||
public int itemLocatedSlot;
|
||||
public boolean baubleFlag;
|
||||
public IEffectData[] effectData = new IEffectData[2];
|
||||
|
||||
public int currentBeeHealth;
|
||||
public int currentBeeColour;
|
||||
public int throttle;
|
||||
|
||||
private final static String KEY_SLOTS = "Slots";
|
||||
private static final String KEY_UID = "UID";
|
||||
private static final Random rand = new Random();
|
||||
private final static String KEY_HEALTH = "Health";
|
||||
private final static String KEY_THROTTLE = "Throttle";
|
||||
|
||||
public InventoryBeeRing(ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
parent = stack;
|
||||
private final static String KEY_EFFECT_1 = "Effect1";
|
||||
private final static String KEY_EFFECT_2 = "Effect2";
|
||||
private final static String KEY_COLOUR = "Colour";
|
||||
|
||||
public InventoryBeeRing(ItemStack stack, EntityPlayer player, int slot, boolean baubleFlag) {
|
||||
this.parent = stack;
|
||||
this.player = player;
|
||||
this.contents = new ItemStack[2];
|
||||
this.itemLocatedSlot = slot;
|
||||
this.baubleFlag = baubleFlag;
|
||||
|
||||
readFromNBT(stack.getTagCompound());
|
||||
}
|
||||
@@ -36,6 +48,7 @@ public class InventoryBeeRing implements IInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initializing slot contents
|
||||
if (compound.hasKey(KEY_SLOTS)) {
|
||||
NBTTagCompound nbtSlots = compound.getCompoundTag(KEY_SLOTS);
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
@@ -49,17 +62,22 @@ public class InventoryBeeRing implements IInventory {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (compound.getInteger("throttle") != 0) {
|
||||
throttle = compound.getInteger("throttle");
|
||||
|
||||
// Initializing Throttle for logic and Health, Colour for GUI effects
|
||||
if (compound.getInteger(KEY_THROTTLE) != 0) {
|
||||
throttle = compound.getInteger(KEY_THROTTLE);
|
||||
}
|
||||
|
||||
if (compound.getInteger("currentBeeHealth") != 0)
|
||||
{
|
||||
currentBeeHealth = compound.getInteger("throttle");
|
||||
if (compound.getInteger(KEY_HEALTH) != 0) {
|
||||
currentBeeHealth = compound.getInteger(KEY_HEALTH);
|
||||
}
|
||||
|
||||
if (compound.getInteger(KEY_COLOUR) != 0) {
|
||||
currentBeeColour = compound.getInteger(KEY_COLOUR);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method for NBT Keys
|
||||
private static String getSlotNBTKey(int i) {
|
||||
return Integer.toString(i, Character.MAX_RADIX);
|
||||
}
|
||||
@@ -110,9 +128,7 @@ public class InventoryBeeRing implements IInventory {
|
||||
|
||||
contents[slot] = stack;
|
||||
|
||||
// I have literally no idea, but for some reason when this is 'this.parent' it doesn't work...
|
||||
|
||||
ItemStack parent = player.getCurrentEquippedItem();
|
||||
ItemStack parent = this.parent;
|
||||
|
||||
NBTTagCompound nbt = parent.getTagCompound();
|
||||
if (nbt == null) {
|
||||
@@ -121,7 +137,7 @@ public class InventoryBeeRing implements IInventory {
|
||||
}
|
||||
|
||||
NBTTagCompound slotNbt;
|
||||
if (!nbt.hasKey("KEY_SLOTS")) {
|
||||
if (!nbt.hasKey(KEY_SLOTS)) {
|
||||
slotNbt = new NBTTagCompound();
|
||||
nbt.setTag(KEY_SLOTS, slotNbt);
|
||||
} else {
|
||||
@@ -138,6 +154,142 @@ public class InventoryBeeRing implements IInventory {
|
||||
|
||||
slotNbt.setTag(slotKey, itemNbt);
|
||||
}
|
||||
|
||||
setInventorySlot(parent);
|
||||
}
|
||||
|
||||
private void setInventorySlot(ItemStack parent) {
|
||||
if (baubleFlag) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(this.player);
|
||||
baubles.setInventorySlotContents(itemLocatedSlot, parent);
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(itemLocatedSlot, parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setCurrentBeeHealth(int health) {
|
||||
this.currentBeeHealth = health;
|
||||
this.parent.getTagCompound().setInteger(KEY_HEALTH, this.currentBeeHealth);
|
||||
setInventorySlot(parent);
|
||||
}
|
||||
|
||||
public void setCurrentBeeColour(int colour) {
|
||||
this.currentBeeColour = colour;
|
||||
this.parent.getTagCompound().setInteger(KEY_COLOUR, this.currentBeeColour);
|
||||
}
|
||||
|
||||
public void setThrottle(int throttle) {
|
||||
this.throttle = throttle;
|
||||
this.parent.getTagCompound().setInteger(KEY_THROTTLE, this.throttle);
|
||||
setInventorySlot(parent);
|
||||
}
|
||||
|
||||
public void writeEffectNBT() {
|
||||
NBTTagCompound compound = parent.getTagCompound();
|
||||
|
||||
if (compound == null) {
|
||||
compound = new NBTTagCompound();
|
||||
parent.setTagCompound(compound);
|
||||
}
|
||||
|
||||
NBTTagCompound slotNbt1;
|
||||
if (!compound.hasKey(KEY_EFFECT_1)) {
|
||||
slotNbt1 = new NBTTagCompound();
|
||||
compound.setTag(KEY_EFFECT_1, slotNbt1);
|
||||
} else {
|
||||
slotNbt1 = compound.getCompoundTag(KEY_EFFECT_1);
|
||||
}
|
||||
|
||||
NBTTagCompound slotNbt2;
|
||||
if (!compound.hasKey(KEY_EFFECT_2)) {
|
||||
slotNbt2 = new NBTTagCompound();
|
||||
compound.setTag(KEY_EFFECT_2, slotNbt2);
|
||||
} else {
|
||||
slotNbt2 = compound.getCompoundTag(KEY_EFFECT_2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String slotKey = getSlotNBTKey(i);
|
||||
try {
|
||||
slotNbt1.setInteger(slotKey + "i", effectData[0].getInteger(i));
|
||||
slotNbt1.setBoolean(slotKey + "b", effectData[0].getBoolean(i));
|
||||
slotNbt1.setFloat(slotKey + "f", effectData[0].getFloat(i));
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String slotKey = getSlotNBTKey(i);
|
||||
try {
|
||||
slotNbt2.setInteger(slotKey + "i", effectData[1].getInteger(i));
|
||||
slotNbt2.setBoolean(slotKey + "b", effectData[1].getBoolean(i));
|
||||
slotNbt2.setFloat(slotKey + "f", effectData[1].getFloat(i));
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
setInventorySlot(parent);
|
||||
}
|
||||
|
||||
public void setEffectAndInitialize(IBee queen) {
|
||||
effectData[0] = queen.getGenome().getEffect().validateStorage(effectData[0]);
|
||||
effectData[1] = ((IAlleleBeeEffect) queen.getGenome().getInactiveAllele(EnumBeeChromosome.EFFECT))
|
||||
.validateStorage(effectData[1]);
|
||||
|
||||
NBTTagCompound compound = parent.getTagCompound();
|
||||
|
||||
if (compound.hasKey(KEY_EFFECT_1)) {
|
||||
NBTTagCompound nbtSlots1 = compound.getCompoundTag(KEY_EFFECT_1);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String slotKey = getSlotNBTKey(i);
|
||||
|
||||
if (nbtSlots1.hasKey(slotKey + "i")) {
|
||||
int effectNBTInt = nbtSlots1.getInteger(slotKey + "i");
|
||||
try {
|
||||
effectData[0].setInteger(i, effectNBTInt);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (nbtSlots1.hasKey(slotKey + "b")) {
|
||||
boolean effectNBTBool = nbtSlots1.getBoolean(slotKey + "b");
|
||||
try {
|
||||
effectData[0].setBoolean(i, effectNBTBool);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (nbtSlots1.hasKey(slotKey + "f")) {
|
||||
float effectNBTFloat = nbtSlots1.getFloat(slotKey + "f");
|
||||
try {
|
||||
effectData[0].setFloat(i, effectNBTFloat);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (compound.hasKey(KEY_EFFECT_2)) {
|
||||
NBTTagCompound nbtSlots2 = compound.getCompoundTag(KEY_EFFECT_2);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String slotKey = getSlotNBTKey(i);
|
||||
|
||||
if (nbtSlots2.hasKey(slotKey + "i")) {
|
||||
int effectNBTInt = nbtSlots2.getInteger(slotKey + "i");
|
||||
try {
|
||||
effectData[1].setInteger(i, effectNBTInt);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (nbtSlots2.hasKey(slotKey + "b")) {
|
||||
boolean effectNBTBool = nbtSlots2.getBoolean(slotKey + "b");
|
||||
try {
|
||||
effectData[1].setBoolean(i, effectNBTBool);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (nbtSlots2.hasKey(slotKey + "f")) {
|
||||
float effectNBTFloat = nbtSlots2.getFloat(slotKey + "f");
|
||||
try {
|
||||
effectData[1].setFloat(i, effectNBTFloat);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,8 +308,7 @@ public class InventoryBeeRing implements IInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
public void markDirty() {}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import magicbees.bees.BeeManager;
|
||||
import magicbees.itemInventories.InventoryBeeRing;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.*;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorState;
|
||||
|
||||
public class RingHousing implements IBeeHousing {
|
||||
|
||||
EntityPlayer player;
|
||||
BiomeGenBase biome;
|
||||
IBeeHousingInventory inventory;
|
||||
IBeekeepingLogic beekeepingLogic;
|
||||
|
||||
private static final IErrorLogic errorLogic = new RingHousing.RingErrorLogic();
|
||||
private static final Iterable<IBeeListener> beeListeners = ImmutableSet.of(new DefaultBeeListener());
|
||||
private static final Iterable<IBeeModifier> beeModifiers = ImmutableSet.of(new RingHousing.RingHousingModifier());
|
||||
|
||||
public RingHousing(EntityPlayer player, InventoryBeeRing IBR) {
|
||||
this.player = player;
|
||||
this.biome = player.getEntityWorld().getBiomeGenForCoords((int) player.posX, (int) player.posY);
|
||||
this.inventory = new RingBeeHousingInventory(IBR);
|
||||
this.beekeepingLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<IBeeModifier> getBeeModifiers() {
|
||||
return beeModifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<IBeeListener> getBeeListeners() {
|
||||
return beeListeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBeekeepingLogic getBeekeepingLogic() {
|
||||
return beekeepingLogic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLightValue() {
|
||||
return player.getEntityWorld()
|
||||
.getBlockLightValue((int) player.posX, ((int) player.posY) + 1, (int) player.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlockSeeTheSky() {
|
||||
return player.getEntityWorld().canBlockSeeTheSky((int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return player.getEntityWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return player.getGameProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 getBeeFXCoordinates() {
|
||||
return Vec3.createVectorHelper(player.posX, player.posY + 0.5, player.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiome() {
|
||||
return this.biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromBiome(biome, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(biome.rainfall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IErrorLogic getErrorLogic() {
|
||||
return errorLogic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getCoordinates() {
|
||||
return player.getPlayerCoordinates();
|
||||
}
|
||||
|
||||
private static class RingBeeHousingInventory implements IBeeHousingInventory {
|
||||
|
||||
private final InventoryBeeRing IBR;
|
||||
|
||||
public RingBeeHousingInventory(InventoryBeeRing IBR) {
|
||||
this.IBR = IBR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getQueen() {
|
||||
return IBR.getStackInSlot(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDrone() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueen(ItemStack itemStack) {
|
||||
IBR.setInventorySlotContents(1, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrone(ItemStack itemstack) {}
|
||||
|
||||
@Override
|
||||
public boolean addProduct(ItemStack product, boolean all) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RingErrorLogic implements IErrorLogic {
|
||||
|
||||
@Override
|
||||
public boolean setCondition(boolean condition, IErrorState errorState) {
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IErrorState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrors() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearErrors() {}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<IErrorState> getErrorStates() {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RingHousingModifier implements IBeeModifier {
|
||||
|
||||
@Override
|
||||
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
|
||||
return 0.9f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSealed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelfLighted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSunlightSimulated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHellish() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user