diff --git a/api/forestry b/api/forestry index 7aafb5e52..6bf135b52 160000 --- a/api/forestry +++ b/api/forestry @@ -1 +1 @@ -Subproject commit 7aafb5e5215d7e2acf70fa96046a21c035adcf43 +Subproject commit 6bf135b52c19480f4a9d3f61392d1ac86f68b1d9 diff --git a/lang b/lang index 284305339..74ea3a324 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 284305339538af7abfdd162b054f1c5e9f05dbd5 +Subproject commit 74ea3a3244edfff6aa3132615c91550fd7ce61ea diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index b7c73f490..5e01953fb 100755 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -17,9 +17,12 @@ import java.util.Collections; import java.util.Set; import java.util.Stack; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import forestry.api.apiculture.BeeManager; @@ -35,7 +38,8 @@ import forestry.api.core.IErrorLogic; import forestry.api.core.IErrorState; import forestry.api.genetics.IEffectData; import forestry.api.genetics.IIndividual; -import forestry.apiculture.network.PacketBeekeepingLogicActive; +import forestry.apiculture.network.PacketBeeLogicActive; +import forestry.apiculture.network.PacketBeeLogicActiveEntity; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; import forestry.core.errors.EnumErrorCode; @@ -418,7 +422,23 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable { public void syncToClient() { World world = housing.getWorld(); if (world != null && !world.isRemote) { - Proxies.net.sendNetworkPacket(new PacketBeekeepingLogicActive(housing), world); + if (housing instanceof TileEntity) { + Proxies.net.sendNetworkPacket(new PacketBeeLogicActive(housing), world); + } else if (housing instanceof Entity) { + Proxies.net.sendNetworkPacket(new PacketBeeLogicActiveEntity(housing, (Entity) housing), world); + } + } + } + + @Override + public void syncToClient(EntityPlayerMP player) { + World world = housing.getWorld(); + if (world != null && !world.isRemote) { + if (housing instanceof TileEntity) { + Proxies.net.sendToPlayer(new PacketBeeLogicActive(housing), player); + } else if (housing instanceof Entity) { + Proxies.net.sendToPlayer(new PacketBeeLogicActiveEntity(housing, (Entity) housing), player); + } } } diff --git a/src/main/java/forestry/apiculture/FakeBeekeepingLogic.java b/src/main/java/forestry/apiculture/FakeBeekeepingLogic.java index ee434027a..9f0ca1c6d 100644 --- a/src/main/java/forestry/apiculture/FakeBeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/FakeBeekeepingLogic.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.apiculture; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import forestry.api.apiculture.IBeekeepingLogic; @@ -36,6 +37,11 @@ public class FakeBeekeepingLogic implements IBeekeepingLogic { } + @Override + public void syncToClient(EntityPlayerMP player) { + + } + @Override public int getBeeProgressPercent() { return 0; diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 3e761a147..2d16314fc 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -10,11 +10,15 @@ ******************************************************************************/ package forestry.apiculture; +import net.minecraft.client.gui.Gui; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.api.apiculture.BeeManager; +import forestry.apiculture.entities.EntityMinecartBeehouse; import forestry.apiculture.gui.ContainerAlveary; import forestry.apiculture.gui.ContainerAlvearyHygroregulator; import forestry.apiculture.gui.ContainerAlvearySieve; @@ -22,6 +26,7 @@ import forestry.apiculture.gui.ContainerAlvearySwarmer; import forestry.apiculture.gui.ContainerBeeHousing; import forestry.apiculture.gui.ContainerHabitatLocator; import forestry.apiculture.gui.ContainerImprinter; +import forestry.apiculture.gui.ContainerMinecartBeehouse; import forestry.apiculture.gui.GuiAlveary; import forestry.apiculture.gui.GuiAlvearyHygroregulator; import forestry.apiculture.gui.GuiAlvearySieve; @@ -42,11 +47,12 @@ import forestry.apiculture.tiles.TileBeehouse; import forestry.core.GuiHandlerBase; import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; +import forestry.core.tiles.TileUtil; public class GuiHandlerApiculture extends GuiHandlerBase { @Override - public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { + public Gui getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { int cleanId = decodeGuiID(id); int guiData = decodeGuiData(id); @@ -58,19 +64,22 @@ public class GuiHandlerApiculture extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AlvearyGUI: - return new GuiAlveary(player.inventory, getTile(world, x, y, z, player, TileAlvearyPlain.class)); + return new GuiAlveary(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyPlain.class)); case AlvearySieveGUI: - return new GuiAlvearySieve(player.inventory, getTile(world, x, y, z, player, TileAlvearySieve.class)); + return new GuiAlvearySieve(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearySieve.class)); case AlvearySwarmerGUI: - return new GuiAlvearySwarmer(player.inventory, getTile(world, x, y, z, player, TileAlvearySwarmer.class)); + return new GuiAlvearySwarmer(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearySwarmer.class)); case ApiaristChestGUI: return getNaturalistChestGui(BeeManager.beeRoot, player, world, x, y, z, guiData); - case ApiaryGUI: - return new GuiBeeHousing(player.inventory, getTile(world, x, y, z, player, TileApiary.class)); + case ApiaryGUI: { + TileApiary tileApiary = TileUtil.getTile(world, x, y, z, TileApiary.class); + ContainerBeeHousing container = new ContainerBeeHousing(player.inventory, tileApiary, true); + return new GuiBeeHousing<>(tileApiary, container, GuiBeeHousing.Icon.APIARY); + } case BeealyzerGUI: equipped = player.getCurrentEquippedItem(); @@ -80,8 +89,22 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiBeealyzer(player, new BeealyzerInventory(player, equipped)); - case BeehouseGUI: - return new GuiBeeHousing(player.inventory, getTile(world, x, y, z, player, TileBeehouse.class)); + case BeehouseGUI: { + TileBeehouse tileBeehouse = TileUtil.getTile(world, x, y, z, TileBeehouse.class); + ContainerBeeHousing container = new ContainerBeeHousing(player.inventory, tileBeehouse, false); + return new GuiBeeHousing<>(tileBeehouse, container, GuiBeeHousing.Icon.BEE_HOUSE); + } + + case MinecartBeehouseGUI: { + Entity entity = world.getEntityByID(x); + if (!(entity instanceof EntityMinecartBeehouse)) { + return null; + } + + EntityMinecartBeehouse beeCart = (EntityMinecartBeehouse) entity; + ContainerMinecartBeehouse container = new ContainerMinecartBeehouse(player.inventory, beeCart, false); + return new GuiBeeHousing<>(beeCart, container, GuiBeeHousing.Icon.BEE_HOUSE); + } case HabitatLocatorGUI: equipped = player.getCurrentEquippedItem(); @@ -92,7 +115,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: - return new GuiAlvearyHygroregulator(player.inventory, getTile(world, x, y, z, player, TileAlvearyHygroregulator.class)); + return new GuiAlvearyHygroregulator(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyHygroregulator.class)); case ImprinterGUI: equipped = player.getCurrentEquippedItem(); @@ -108,7 +131,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { } @Override - public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { + public Container getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { int cleanId = decodeGuiID(id); int guiData = decodeGuiData(id); @@ -121,20 +144,20 @@ public class GuiHandlerApiculture extends GuiHandlerBase { case AlvearyGUI: synchApiaristTracker(world, player); - return new ContainerAlveary(player.inventory, getTile(world, x, y, z, player, TileAlvearyPlain.class)); + return new ContainerAlveary(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyPlain.class)); case AlvearySieveGUI: - return new ContainerAlvearySieve(player.inventory, getTile(world, x, y, z, player, TileAlvearySieve.class)); + return new ContainerAlvearySieve(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearySieve.class)); case AlvearySwarmerGUI: - return new ContainerAlvearySwarmer(player.inventory, getTile(world, x, y, z, player, TileAlvearySwarmer.class)); + return new ContainerAlvearySwarmer(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearySwarmer.class)); case ApiaristChestGUI: return getNaturalistChestContainer(BeeManager.beeRoot, player, world, x, y, z, guiData); case ApiaryGUI: synchApiaristTracker(world, player); - return new ContainerBeeHousing(player.inventory, getTile(world, x, y, z, player, TileApiary.class), true); + return new ContainerBeeHousing(player.inventory, TileUtil.getTile(world, x, y, z, TileApiary.class), true); case BeealyzerGUI: equipped = player.getCurrentEquippedItem(); @@ -147,7 +170,17 @@ public class GuiHandlerApiculture extends GuiHandlerBase { case BeehouseGUI: synchApiaristTracker(world, player); - return new ContainerBeeHousing(player.inventory, getTile(world, x, y, z, player, TileBeehouse.class), false); + return new ContainerBeeHousing(player.inventory, TileUtil.getTile(world, x, y, z, TileBeehouse.class), false); + + case MinecartBeehouseGUI: { + Entity entity = world.getEntityByID(x); + if (!(entity instanceof EntityMinecartBeehouse)) { + return null; + } + + synchApiaristTracker(world, player); + return new ContainerMinecartBeehouse(player.inventory, (EntityMinecartBeehouse) entity, false); + } case HabitatLocatorGUI: equipped = player.getCurrentEquippedItem(); @@ -158,7 +191,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new ContainerHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: - return new ContainerAlvearyHygroregulator(player.inventory, getTile(world, x, y, z, player, TileAlvearyHygroregulator.class)); + return new ContainerAlvearyHygroregulator(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyHygroregulator.class)); case ImprinterGUI: synchApiaristTracker(world, player); diff --git a/src/main/java/forestry/apiculture/HasFlowersCache.java b/src/main/java/forestry/apiculture/HasFlowersCache.java index 47ca8d73b..6b4a1ae44 100644 --- a/src/main/java/forestry/apiculture/HasFlowersCache.java +++ b/src/main/java/forestry/apiculture/HasFlowersCache.java @@ -16,11 +16,14 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; +import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.FlowerManager; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeModifier; import forestry.api.core.INBTTagable; import forestry.api.genetics.IFlowerProvider; +import forestry.core.utils.vect.Vect; import forestry.plugins.PluginApiculture; public class HasFlowersCache implements INBTTagable { @@ -42,7 +45,16 @@ public class HasFlowersCache implements INBTTagable { return true; } - if (FlowerManager.flowerRegistry.isAcceptedFlower(flowerType, world, flowerCoords.posX, flowerCoords.posY, flowerCoords.posZ)) { + IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(beeHousing); + ChunkCoordinates housingCoords = beeHousing.getCoordinates(); + + int[] genomeTerritory = queen.getGenome().getTerritory(); + float housingModifier = beeModifier.getTerritoryModifier(queen.getGenome(), 1f); + Vect area = new Vect(genomeTerritory).multiply(housingModifier * 3.0f); + Vect min = new Vect(area).multiply(-0.5f).add(housingCoords); + Vect max = new Vect(area).multiply(0.5f).add(housingCoords); + + if (isFlowerValid(world, flowerType, min, max)) { return true; } else { flowerCoords = null; @@ -60,6 +72,17 @@ public class HasFlowersCache implements INBTTagable { return flowerCoords != null; } + private boolean isFlowerValid(World world, String flowerType, Vect min, Vect max) { + if (!isFlowerCoordInRange(flowerCoords, min, max)) { + return false; + } + return FlowerManager.flowerRegistry.isAcceptedFlower(flowerType, world, flowerCoords.posX, flowerCoords.posY, flowerCoords.posZ); + } + + private static boolean isFlowerCoordInRange(ChunkCoordinates flowerCoords, Vect min, Vect max) { + return flowerCoords.posX >= min.x && flowerCoords.posX <= max.x && flowerCoords.posY >= min.y && flowerCoords.posY <= max.y && flowerCoords.posZ >= min.z && flowerCoords.posZ <= max.z; + } + @Override public void readFromNBT(NBTTagCompound nbttagcompound) { if (!nbttagcompound.hasKey(nbtKey)) { diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java new file mode 100644 index 000000000..8cbd37c05 --- /dev/null +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java @@ -0,0 +1,393 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.entities; + +import com.google.common.collect.ImmutableList; + +import java.io.IOException; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityMinecartContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.DamageSource; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import com.mojang.authlib.GameProfile; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.minecart.MinecartInteractEvent; + +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.DefaultBeeListener; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeHousingInventory; +import forestry.api.apiculture.IBeeListener; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ForestryAPI; +import forestry.api.core.IErrorLogic; +import forestry.apiculture.gui.IGuiBeeHousingInventory; +import forestry.apiculture.network.PacketBeeLogicEntityRequest; +import forestry.apiculture.tiles.TileAbstractBeeHousing; +import forestry.apiculture.tiles.TileBeehouse; +import forestry.core.access.AccessHandler; +import forestry.core.access.EnumAccess; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; +import forestry.core.config.Config; +import forestry.core.config.Constants; +import forestry.core.config.ForestryBlock; +import forestry.core.config.ForestryItem; +import forestry.core.gui.IHintSource; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.IStreamableGui; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.IClimatised; +import forestry.core.tiles.IFilterSlotDelegate; +import forestry.core.utils.InventoryUtil; + +public class EntityMinecartBeehouse extends EntityMinecartContainer implements IBeeHousing, IFilterSlotDelegate, IGuiBeeHousingInventory, IStreamableGui, IRestrictedAccess, IClimatised, IHintSource { + private static final Random random = new Random(); + private static final int beeFXInterval = 4; + private static final int pollenFXInterval = 50; + + private final int beeFXTime = random.nextInt(beeFXInterval); + private final int pollenFXTime = random.nextInt(pollenFXInterval); + + private static final Iterable beeModifiers = ImmutableList.of(new TileBeehouse.BeehouseBeeModifier()); + private static final Iterable beeListeners = ImmutableList.of(new DefaultBeeListener()); + + private final IBeekeepingLogic beeLogic; + private final IErrorLogic errorLogic; + private final BeeCartInventory beeInventory; + private final AccessHandler accessHandler; + + // CLIENT + private int breedingProgressPercent = 0; + private boolean needsActiveUpdate = true; + + public EntityMinecartBeehouse(World world) { + super(world); + setHasDisplayTile(true); + this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); + this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); + this.beeInventory = new BeeCartInventory(this); + this.accessHandler = new AccessHandler(this); + } + + public EntityMinecartBeehouse(World world, double posX, double posY, double posZ) { + super(world, posX, posY, posZ); + setHasDisplayTile(true); + this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); + this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); + this.beeInventory = new BeeCartInventory(this); + this.accessHandler = new AccessHandler(this); + } + + @Override + public final boolean interactFirst(EntityPlayer player) { + if (MinecraftForge.EVENT_BUS.post(new MinecartInteractEvent(this, player))) { + return true; + } + + if (!worldObj.isRemote) { + player.openGui(ForestryAPI.instance, GuiId.MinecartBeehouseGUI.ordinal(), worldObj, getEntityId(), -1, 0); + } + return true; + } + + public void setOwner(GameProfile owner) { + accessHandler.setOwner(owner); + } + + @Override + public int getMinecartType() { + return -1; + } + + @Override + public int getSizeInventory() { + return 9; + } + + /* IBeeHousing */ + @Override + public Iterable getBeeModifiers() { + return beeModifiers; + } + + @Override + public Iterable getBeeListeners() { + return beeListeners; + } + + @Override + public BeeCartInventory getBeeInventory() { + return beeInventory; + } + + @Override + public IBeekeepingLogic getBeekeepingLogic() { + return beeLogic; + } + + @Override + public EnumTemperature getTemperature() { + return EnumTemperature.getFromBiome(getBiome()); + } + + @Override + public EnumHumidity getHumidity() { + return EnumHumidity.getFromValue(getBiome().rainfall); + } + + @Override + public float getExactTemperature() { + return getBiome().temperature; + } + + @Override + public float getExactHumidity() { + return getBiome().rainfall; + } + + @Override + public int getBlockLightValue() { + return worldObj.getBlockLightValue((int) posX, (int) posY, (int) posZ); + } + + @Override + public boolean canBlockSeeTheSky() { + return worldObj.canBlockSeeTheSky((int) posX, (int) posY, (int) posZ); + } + + @Override + public World getWorld() { + return worldObj; + } + + @Override + public BiomeGenBase getBiome() { + return worldObj.getBiomeGenForCoords((int) posX, (int) posZ); + } + + @Override + public GameProfile getOwner() { + return accessHandler.getOwner(); + } + + @Override + public IErrorLogic getErrorLogic() { + return errorLogic; + } + + @Override + public ChunkCoordinates getCoordinates() { + return new ChunkCoordinates((int) posX, (int) posY, (int) posZ); + } + + @Override + public Vec3 getBeeFXCoordinates() { + return Vec3.createVectorHelper(posX, posY + 0.25, posZ); + } + + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + data.writeVarInt(beeLogic.getBeeProgressPercent()); + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + breedingProgressPercent = data.readVarInt(); + } + + /** + * Returns scaled queen health or breeding progress + */ + public int getHealthScaled(int i) { + return (breedingProgressPercent * i) / 100; + } + + @Override + public void onUpdate() { + super.onUpdate(); + if (!worldObj.isRemote) { + if (beeLogic.canWork()) { + beeLogic.doWork(); + } + } else { + if (needsActiveUpdate) { + IForestryPacketServer packet = new PacketBeeLogicEntityRequest(this); + Proxies.net.sendToServer(packet); + needsActiveUpdate = false; + } + + if (beeLogic.canDoBeeFX()) { + if (worldObj.getTotalWorldTime() % beeFXInterval == beeFXTime) { + beeLogic.doBeeFX(); + } + + if (worldObj.getTotalWorldTime() % pollenFXInterval == pollenFXTime) { + TileAbstractBeeHousing.doPollenFX(worldObj, posX - 0.5, posY - 0.1, posZ - 0.5); + } + } + } + } + + @Override + protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) { + super.readEntityFromNBT(nbtTagCompound); + beeLogic.readFromNBT(nbtTagCompound); + accessHandler.readFromNBT(nbtTagCompound); + } + + @Override + protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) { + super.writeEntityToNBT(nbtTagCompound); + beeLogic.writeToNBT(nbtTagCompound); + accessHandler.writeToNBT(nbtTagCompound); + } + + /* IFilterSlotDelegate */ + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + EnumBeeType beeType = BeeManager.beeRoot.getType(itemStack); + + if (slotIndex == BeeCartInventory.SLOT_QUEEN) { + return beeType == EnumBeeType.QUEEN || beeType == EnumBeeType.PRINCESS; + } else if (slotIndex == BeeCartInventory.SLOT_DRONE) { + return beeType == EnumBeeType.DRONE; + } + return false; + } + + @Override + public boolean isLocked(int slotIndex) { + return false; + } + + /* ITitled */ + @Override + public String getUnlocalizedTitle() { + return "entity." + getEntityString() + ".name"; + } + + @Override + public boolean canBeRidden() { + return false; + } + + @Override + public Block func_145820_n() { + return ForestryBlock.apiculture.block(); + } + + @Override + public int getDisplayTileData() { + return Constants.DEFINITION_BEEHOUSE_META; + } + + @Override + public void killMinecart(DamageSource damageSource) { + super.killMinecart(damageSource); + + if (!damageSource.isExplosion()) { + entityDropItem(new ItemStack(func_145820_n(), 1, getDisplayTileData()), 0.0F); + } + } + + @Override + public void setDead() { + // stop ghost items from dropping client side + if (worldObj.isRemote) { + for (int slot = 0; slot < getSizeInventory(); slot++) { + setInventorySlotContents(slot, null); + } + } + super.setDead(); + } + + @Override + public ItemStack getCartItem() { + return ForestryItem.minecartBeehouse.getItemStack(); + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemStack) { + return canSlotAccept(slot, itemStack); + } + + @Override + public IAccessHandler getAccessHandler() { + return accessHandler; + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + + } + + @Override + public String[] getHints() { + return Config.hints.get("apiary"); + } + + private static class BeeCartInventory implements IBeeHousingInventory { + public static final int SLOT_QUEEN = 0; + public static final int SLOT_DRONE = 1; + public static final int SLOT_PRODUCT_1 = 2; + public static final int SLOT_PRODUCT_COUNT = 7; + + private final EntityMinecartBeehouse cart; + + public BeeCartInventory(EntityMinecartBeehouse cart) { + this.cart = cart; + } + + @Override + public final ItemStack getQueen() { + return cart.getStackInSlot(SLOT_QUEEN); + } + + @Override + public final ItemStack getDrone() { + return cart.getStackInSlot(SLOT_DRONE); + } + + @Override + public final void setQueen(ItemStack itemstack) { + cart.setInventorySlotContents(SLOT_QUEEN, itemstack); + } + + @Override + public final void setDrone(ItemStack itemstack) { + cart.setInventorySlotContents(SLOT_DRONE, itemstack); + } + + @Override + public final boolean addProduct(ItemStack product, boolean all) { + return InventoryUtil.tryAddStack(cart, product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all, true); + } + } + +} diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffect.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffect.java index 59d7c305d..ea274251b 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffect.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffect.java @@ -11,6 +11,8 @@ package forestry.apiculture.genetics.alleles; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Vec3; import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.IAlleleBeeEffect; @@ -66,10 +68,21 @@ public abstract class AlleleEffect extends AlleleCategorized implements IAlleleB @Override public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) { - Proxies.render.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), housing.getCoordinates(), genome.getPrimary().getIconColour(0)); + Vec3 beeFXCoordinates = getFXCoordinates(housing); + Proxies.render.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord, beeFXCoordinates.zCoord, genome.getPrimary().getIconColour(0)); return storedData; } + protected Vec3 getFXCoordinates(IBeeHousing housing) { + try { + return housing.getBeeFXCoordinates(); + } catch (Throwable error) { + // getBeeFXCoordinates() is only newly added to the API, fall back on getCoordinates() + ChunkCoordinates coordinates = housing.getCoordinates(); + return Vec3.createVectorHelper(coordinates.posX + 0.5D, coordinates.posY + 0.5D, coordinates.posZ + 0.5D); + } + } + protected Vect getModifiedArea(IBeeGenome genome, IBeeHousing housing) { IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing); float territoryModifier = beeModifier.getTerritoryModifier(genome, 1f); diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectIgnition.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectIgnition.java index 6101008df..ed0b5ce93 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectIgnition.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectIgnition.java @@ -15,6 +15,7 @@ import java.util.List; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import forestry.api.apiculture.BeeManager; @@ -80,7 +81,8 @@ public class AlleleEffectIgnition extends AlleleEffectThrottled { if (housing.getWorld().rand.nextInt(2) != 0) { super.doFX(genome, storedData, housing); } else { - Proxies.render.addEntityIgnitionFX(housing.getWorld(), housing.getCoordinates().posX + 0.5, housing.getCoordinates().posY + 1, housing.getCoordinates().posZ + 0.5); + Vec3 beeFXCoordinates = getFXCoordinates(housing); + Proxies.render.addEntityIgnitionFX(housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord + 0.5, beeFXCoordinates.zCoord); } return storedData; } diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java index 7d56cfe5e..5d5d8ac06 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java @@ -19,7 +19,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionHelper; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import cpw.mods.fml.relauncher.ReflectionHelper; @@ -108,8 +108,8 @@ public class AlleleEffectPotion extends AlleleEffectThrottled { if (housing.getWorld().rand.nextBoolean()) { super.doFX(genome, storedData, housing); } else { - ChunkCoordinates coords = housing.getCoordinates(); - Proxies.render.addEntityPotionFX(housing.getWorld(), coords.posX + 0.5, coords.posY + 1, coords.posZ + 0.5, potionFXColor); + Vec3 beeFXCoordinates = getFXCoordinates(housing); + Proxies.render.addEntityPotionFX(housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord + 0.5, beeFXCoordinates.zCoord, potionFXColor); } return storedData; } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java index 8b0740e69..fb89622d3 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java @@ -12,32 +12,15 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; -import forestry.apiculture.BeeHousingInventory; import forestry.apiculture.multiblock.TileAlvearyPlain; import forestry.core.gui.ContainerTile; -import forestry.core.gui.slots.SlotFiltered; -import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketGuiUpdate; public class ContainerAlveary extends ContainerTile { public ContainerAlveary(InventoryPlayer player, TileAlvearyPlain tile) { super(tile, player, 8, 108); - - // Queen/Princess - this.addSlotToContainer(new SlotFiltered(tile, BeeHousingInventory.SLOT_QUEEN, 29, 39)); - - // Drone - this.addSlotToContainer(new SlotFiltered(tile, BeeHousingInventory.SLOT_DRONE, 29, 65)); - - // Product Inventory - this.addSlotToContainer(new SlotOutput(tile, 2, 116, 52)); - this.addSlotToContainer(new SlotOutput(tile, 3, 137, 39)); - this.addSlotToContainer(new SlotOutput(tile, 4, 137, 65)); - this.addSlotToContainer(new SlotOutput(tile, 5, 116, 78)); - this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); - this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); - this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); + ContainerBeeHelper.addSlots(this, tile, false); } @Override diff --git a/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java b/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java new file mode 100644 index 000000000..d17f8936f --- /dev/null +++ b/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.gui; + +import net.minecraft.inventory.IInventory; + +import forestry.apiculture.BeeHousingInventory; +import forestry.apiculture.tiles.TileApiary; +import forestry.core.gui.ContainerForestry; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; +import forestry.core.tiles.IFilterSlotDelegate; + +public abstract class ContainerBeeHelper { + public static void addSlots(ContainerForestry container, T inventory, boolean hasFrames) { + // Queen/Princess + container.addSlotToContainer(new SlotFiltered(inventory, BeeHousingInventory.SLOT_QUEEN, 29, 39)); + + // Drone + container.addSlotToContainer(new SlotFiltered(inventory, BeeHousingInventory.SLOT_DRONE, 29, 65)); + + // Frames + if (hasFrames) { + int slotFrames = TileApiary.ApiaryInventory.SLOT_FRAMES_1; + container.addSlotToContainer(new SlotFiltered(inventory, slotFrames++, 66, 23)); + container.addSlotToContainer(new SlotFiltered(inventory, slotFrames++, 66, 52)); + container.addSlotToContainer(new SlotFiltered(inventory, slotFrames, 66, 81)); + } + + // Product Inventory + int slotProduct = BeeHousingInventory.SLOT_PRODUCT_1; + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 116, 52)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 137, 39)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 137, 65)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 116, 78)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 95, 65)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 95, 39)); + container.addSlotToContainer(new SlotOutput(inventory, slotProduct, 116, 26)); + } +} diff --git a/src/main/java/forestry/apiculture/gui/ContainerBeeHousing.java b/src/main/java/forestry/apiculture/gui/ContainerBeeHousing.java index f9c60932c..fab74ee20 100644 --- a/src/main/java/forestry/apiculture/gui/ContainerBeeHousing.java +++ b/src/main/java/forestry/apiculture/gui/ContainerBeeHousing.java @@ -11,54 +11,30 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import forestry.apiculture.BeeHousingInventory; import forestry.apiculture.tiles.TileAbstractBeeHousing; -import forestry.apiculture.tiles.TileApiary; import forestry.core.gui.ContainerTile; -import forestry.core.gui.slots.SlotFiltered; -import forestry.core.gui.slots.SlotOutput; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.PacketGuiUpdate; -public class ContainerBeeHousing extends ContainerTile { +public class ContainerBeeHousing extends ContainerTile implements IContainerBeeHousing { public ContainerBeeHousing(InventoryPlayer player, TileAbstractBeeHousing tile, boolean hasFrames) { super(tile, player, 8, 108); - - // Queen/Princess - this.addSlotToContainer(new SlotFiltered(tile, BeeHousingInventory.SLOT_QUEEN, 29, 39)); - - // Drone - this.addSlotToContainer(new SlotFiltered(tile, BeeHousingInventory.SLOT_DRONE, 29, 65)); - - // Frames - if (hasFrames) { - final int slotFrames1 = TileApiary.ApiaryInventory.SLOT_FRAMES_1; - this.addSlotToContainer(new SlotFiltered(tile, slotFrames1, 66, 23)); - this.addSlotToContainer(new SlotFiltered(tile, slotFrames1 + 1, 66, 52)); - this.addSlotToContainer(new SlotFiltered(tile, slotFrames1 + 2, 66, 81)); - } - - // Product Inventory - this.addSlotToContainer(new SlotOutput(tile, 2, 116, 52)); - this.addSlotToContainer(new SlotOutput(tile, 3, 137, 39)); - this.addSlotToContainer(new SlotOutput(tile, 4, 137, 65)); - this.addSlotToContainer(new SlotOutput(tile, 5, 116, 78)); - this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); - this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); - this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); + ContainerBeeHelper.addSlots(this, tile, hasFrames); } - @Override - public void updateProgressBar(int i, int j) { - tile.getGUINetworkData(i, j); - } + private int beeProgress = 0; @Override public void detectAndSendChanges() { super.detectAndSendChanges(); - for (Object crafter : crafters) { - tile.sendGUINetworkData(this, (ICrafting) crafter); + + int beeProgress = tile.getBeekeepingLogic().getBeeProgressPercent(); + if (this.beeProgress != beeProgress) { + this.beeProgress = beeProgress; + IForestryPacketClient packet = new PacketGuiUpdate(tile); + sendPacketToCrafters(packet); } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerMinecartBeehouse.java b/src/main/java/forestry/apiculture/gui/ContainerMinecartBeehouse.java new file mode 100644 index 000000000..715c3af7c --- /dev/null +++ b/src/main/java/forestry/apiculture/gui/ContainerMinecartBeehouse.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.apiculture.entities.EntityMinecartBeehouse; +import forestry.core.gui.ContainerEntity; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.PacketGuiUpdateEntity; + +public class ContainerMinecartBeehouse extends ContainerEntity implements IContainerBeeHousing { + public ContainerMinecartBeehouse(InventoryPlayer player, EntityMinecartBeehouse entity, boolean hasFrames) { + super(entity, player, 8, 108); + ContainerBeeHelper.addSlots(this, entity, hasFrames); + } + + private int beeProgress = 0; + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + int beeProgress = entity.getBeekeepingLogic().getBeeProgressPercent(); + if (this.beeProgress != beeProgress) { + this.beeProgress = beeProgress; + IForestryPacketClient packet = new PacketGuiUpdateEntity(entity, entity); + sendPacketToCrafters(packet); + } + } + +} diff --git a/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java b/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java index 9a570db25..45d62dd9c 100644 --- a/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java @@ -10,26 +10,27 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; -import forestry.apiculture.tiles.TileAbstractBeeHousing; -import forestry.apiculture.tiles.TileApiary; -import forestry.apiculture.tiles.TileBeehouse; import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import forestry.core.render.EnumTankLevel; -public class GuiBeeHousing extends GuiForestryTitled { +public class GuiBeeHousing extends GuiForestryTitled { - public GuiBeeHousing(InventoryPlayer inventory, TileApiary tile) { - super(Constants.TEXTURE_PATH_GUI + "/apiary.png", new ContainerBeeHousing(inventory, tile, true), tile); + public enum Icon { + APIARY("/apiary.png"), + BEE_HOUSE("/alveary.png"); - ySize = 190; + private final String path; + + Icon(String path) { + this.path = path; + } } - public GuiBeeHousing(InventoryPlayer inventory, TileBeehouse tile) { - super(Constants.TEXTURE_PATH_GUI + "/alveary.png", new ContainerBeeHousing(inventory, tile, false), tile); - + public GuiBeeHousing(IGuiBeeHousingInventory tile, C container, Icon icon) { + super(Constants.TEXTURE_PATH_GUI + icon.path, container, tile); ySize = 190; } diff --git a/src/main/java/forestry/apiculture/gui/IContainerBeeHousing.java b/src/main/java/forestry/apiculture/gui/IContainerBeeHousing.java new file mode 100644 index 000000000..655b91f51 --- /dev/null +++ b/src/main/java/forestry/apiculture/gui/IContainerBeeHousing.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.gui; + +public interface IContainerBeeHousing { +} diff --git a/src/main/java/forestry/apiculture/gui/IGuiBeeHousingInventory.java b/src/main/java/forestry/apiculture/gui/IGuiBeeHousingInventory.java new file mode 100644 index 000000000..de37d8878 --- /dev/null +++ b/src/main/java/forestry/apiculture/gui/IGuiBeeHousingInventory.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.gui; + +import net.minecraft.inventory.IInventory; + +import forestry.core.tiles.ITitled; + +public interface IGuiBeeHousingInventory extends ITitled, IInventory { + /** Returns scaled queen health or breeding progress */ + int getHealthScaled(int i); +} diff --git a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java index 6ca543003..2b5f7dae9 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java +++ b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java @@ -51,14 +51,7 @@ public class ItemBeealyzer extends ItemAlyzer { return BeeManager.beeRoot; } - - // / IHINTSOURCE - @Override - public boolean hasHints() { - return Config.hints.get("beealyzer") != null && Config.hints.get("beealyzer").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("beealyzer"); diff --git a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java index 557dbf8e6..2364cef78 100644 --- a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java +++ b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java @@ -326,11 +326,6 @@ public class ItemHabitatLocator extends ItemInventoried { } // / IHINTSOURCE - @Override - public boolean hasHints() { - return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("habitatlocator"); diff --git a/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java b/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java new file mode 100644 index 000000000..ef2ff3d1e --- /dev/null +++ b/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.items; + +import net.minecraft.block.BlockDispenser; +import net.minecraft.block.BlockRailBase; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemMinecart; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import forestry.apiculture.entities.EntityMinecartBeehouse; +import forestry.core.render.TextureManager; +import forestry.core.utils.StringUtil; + +public class ItemMinecartBeehouse extends ItemMinecart { + + public ItemMinecartBeehouse() { + super(0); + maxStackSize = 1; + setMaxDamage(0); + setHasSubtypes(false); + BlockDispenser.dispenseBehaviorRegistry.putObject(this, null); + } + + @Override + public void registerIcons(IIconRegister register) { + itemIcon = TextureManager.registerTex(register, StringUtil.cleanItemName(this)); + } + + @Override + public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float facingX, float facingY, float facingZ) { + if (!BlockRailBase.func_150051_a(world.getBlock(x, y, z))) { + return false; + } + + if (!world.isRemote) { + EntityMinecartBeehouse entityMinecart = new EntityMinecartBeehouse(world, (double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F)); + entityMinecart.setOwner(player.getGameProfile()); + + if (itemStack.hasDisplayName()) { + entityMinecart.setMinecartName(itemStack.getDisplayName()); + } + + world.spawnEntityInWorld(entityMinecart); + } + + --itemStack.stackSize; + return true; + } +} diff --git a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java index 3b2908fd3..ee954a05c 100644 --- a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java @@ -18,6 +18,7 @@ import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.StatCollector; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -46,7 +47,6 @@ import forestry.core.multiblock.MultiblockValidationException; import forestry.core.multiblock.rectangular.RectangularMultiblockControllerBase; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; -import forestry.core.network.PacketGuiUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.BlockUtil; @@ -359,10 +359,13 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple } @Override - public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { - PacketGuiUpdate packet = new PacketGuiUpdate(this); - Proxies.net.sendNetworkPacket(packet, worldObj); + public Vec3 getBeeFXCoordinates() { + CoordTriplet coord = getCenterCoord(); + return Vec3.createVectorHelper(coord.x + 0.5, coord.y + 1.5, coord.z + 0.5); + } + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) { // pipes connected to this need to update for (IMultiblockPart part : connectedParts) { @@ -460,7 +463,6 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple @Override public void writeGuiData(DataOutputStreamForestry data) throws IOException { - super.writeGuiData(data); data.writeVarInt(beekeepingLogic.getBeeProgressPercent()); data.writeVarInt(Math.round(tempChange * 100)); data.writeVarInt(Math.round(humidChange * 100)); @@ -468,7 +470,6 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple @Override public void readGuiData(DataInputStreamForestry data) throws IOException { - super.readGuiData(data); breedingProgressPercent = data.readVarInt(); tempChange = data.readVarInt() / 100.0F; humidChange = data.readVarInt() / 100.0F; diff --git a/src/main/java/forestry/apiculture/multiblock/FakeAlvearyController.java b/src/main/java/forestry/apiculture/multiblock/FakeAlvearyController.java index 8018c1357..4fbf8236b 100644 --- a/src/main/java/forestry/apiculture/multiblock/FakeAlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/FakeAlvearyController.java @@ -15,6 +15,7 @@ import java.util.Collections; 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; @@ -120,6 +121,11 @@ public class FakeAlvearyController implements IAlvearyController { return null; } + @Override + public Vec3 getBeeFXCoordinates() { + return null; + } + @Override public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { diff --git a/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java b/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java index e921193e5..93ba94a1c 100644 --- a/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java @@ -12,11 +12,12 @@ package forestry.apiculture.multiblock; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBeeHousing; +import forestry.core.access.IRestrictedAccess; import forestry.core.inventory.IInventoryAdapter; +import forestry.core.network.IStreamableGui; import forestry.core.tiles.IClimatised; -import forestry.core.tiles.IRestrictedAccessTile; -public interface IAlvearyController extends IBeeHousing, IClimatised, IRestrictedAccessTile { +public interface IAlvearyController extends IBeeHousing, IClimatised, IRestrictedAccess, IStreamableGui { IInventoryAdapter getInternalInventory(); Iterable getComponents(); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java index f5059781b..a50b4d506 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.apiculture.multiblock; -import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.StatCollector; -import net.minecraft.world.World; +import net.minecraft.util.Vec3; import net.minecraft.world.biome.BiomeGenBase; import forestry.api.apiculture.IBeeHousing; @@ -24,11 +23,14 @@ import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.IErrorLogic; import forestry.apiculture.blocks.BlockAlveary; +import forestry.core.access.EnumAccess; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; import forestry.core.multiblock.MultiblockControllerBase; import forestry.core.multiblock.MultiblockValidationException; import forestry.core.multiblock.rectangular.RectangularMultiblockTileEntityBase; -public abstract class TileAlveary extends RectangularMultiblockTileEntityBase implements IBeeHousing { +public abstract class TileAlveary extends RectangularMultiblockTileEntityBase implements IBeeHousing, IRestrictedAccess { public static final int PLAIN_META = 0; public static final int ENTRANCE_META = 1; @@ -111,16 +113,6 @@ public abstract class TileAlveary extends RectangularMultiblockTileEntityBase im } /* IHousing */ - @Override - public World getWorld() { - return getAlvearyController().getWorld(); - } - - @Override - public ChunkCoordinates getCoordinates() { - return getAlvearyController().getCoordinates(); - } - @Override public BiomeGenBase getBiome() { return getAlvearyController().getBiome(); @@ -147,6 +139,11 @@ public abstract class TileAlveary extends RectangularMultiblockTileEntityBase im return getAlvearyController().getBeekeepingLogic(); } + @Override + public Vec3 getBeeFXCoordinates() { + return getAlvearyController().getBeeFXCoordinates(); + } + /* IClimatised */ @Override public EnumTemperature getTemperature() { @@ -173,4 +170,13 @@ public abstract class TileAlveary extends RectangularMultiblockTileEntityBase im return getAlvearyController().getErrorLogic(); } + @Override + public IAccessHandler getAccessHandler() { + return getAlvearyController().getAccessHandler(); + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + getAlvearyController().onSwitchAccess(oldAccess, newAccess); + } } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java index ce40501d7..dbc51d72d 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java @@ -11,7 +11,6 @@ package forestry.apiculture.multiblock; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChunkCoordinates; import net.minecraftforge.common.util.ForgeDirection; @@ -134,11 +133,6 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner } } - @Override - public ChunkCoordinates getCoordinates() { - return new ChunkCoordinates(xCoord, yCoord, zCoord); - } - /* IEnergyHandler */ @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java index 903d8880e..3eef23b7b 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java @@ -42,7 +42,7 @@ import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") -public class TileAlvearyPlain extends TileAlveary implements IClimatised, IHintSource, IStreamableGui, ITitled, ITriggerProvider { +public class TileAlvearyPlain extends TileAlveary implements IClimatised, IHintSource, ITitled, ITriggerProvider, IStreamableGui { @Override public void onMachineAssembled(MultiblockControllerBase controller) { @@ -86,6 +86,7 @@ public class TileAlvearyPlain extends TileAlveary implements IClimatised, IHintS } } + /* IStreamableGui */ @Override public void writeGuiData(DataOutputStreamForestry data) throws IOException { getAlvearyController().writeGuiData(data); @@ -98,15 +99,10 @@ public class TileAlvearyPlain extends TileAlveary implements IClimatised, IHintS @Override public String getUnlocalizedTitle() { - return "alveary.0.name"; + return "tile.for.alveary.0.name"; } /* IHintSource */ - @Override - public boolean hasHints() { - return Config.hints.get("apiary").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("apiary"); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java index 6c3bcfc9c..f894b922f 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.apiculture.multiblock; -import java.io.IOException; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChunkCoordinates; @@ -20,13 +18,11 @@ import forestry.api.core.ForestryAPI; import forestry.core.access.AccessHandler; import forestry.core.access.EnumAccess; import forestry.core.access.IAccessHandler; -import forestry.core.network.DataInputStreamForestry; -import forestry.core.network.DataOutputStreamForestry; +import forestry.core.access.IRestrictedAccess; import forestry.core.network.GuiId; -import forestry.core.tiles.IRestrictedAccessTile; import forestry.core.tiles.ITitled; -public abstract class TileAlvearyWithGui extends TileAlveary implements ITitled, IRestrictedAccessTile { +public abstract class TileAlvearyWithGui extends TileAlveary implements ITitled, IRestrictedAccess { private final AccessHandler accessHandler; private final String unlocalizedTitle; @@ -34,7 +30,7 @@ public abstract class TileAlvearyWithGui extends TileAlveary implements ITitled, protected TileAlvearyWithGui(int meta, GuiId guiId) { this.accessHandler = new AccessHandler(this); - this.unlocalizedTitle = "alveary." + meta + ".name"; + this.unlocalizedTitle = "tile.for.alveary." + meta + ".name"; this.guiId = guiId; } @@ -69,16 +65,6 @@ public abstract class TileAlvearyWithGui extends TileAlveary implements ITitled, accessHandler.readFromNBT(data); } - @Override - public void writeGuiData(DataOutputStreamForestry data) throws IOException { - accessHandler.writeData(data); - } - - @Override - public void readGuiData(DataInputStreamForestry data) throws IOException { - accessHandler.readData(data); - } - @Override public final String getUnlocalizedTitle() { return unlocalizedTitle; diff --git a/src/main/java/forestry/apiculture/network/PacketBeekeepingLogicActive.java b/src/main/java/forestry/apiculture/network/PacketBeeLogicActive.java similarity index 88% rename from src/main/java/forestry/apiculture/network/PacketBeekeepingLogicActive.java rename to src/main/java/forestry/apiculture/network/PacketBeeLogicActive.java index 64020ad75..3a40061a2 100644 --- a/src/main/java/forestry/apiculture/network/PacketBeekeepingLogicActive.java +++ b/src/main/java/forestry/apiculture/network/PacketBeeLogicActive.java @@ -25,13 +25,13 @@ import forestry.core.network.PacketCoordinates; import forestry.core.network.PacketIdClient; import forestry.core.proxy.Proxies; -public class PacketBeekeepingLogicActive extends PacketCoordinates implements IForestryPacketClient { +public class PacketBeeLogicActive extends PacketCoordinates implements IForestryPacketClient { private BeekeepingLogic beekeepingLogic; - public PacketBeekeepingLogicActive() { + public PacketBeeLogicActive() { } - public PacketBeekeepingLogicActive(IBeeHousing tile) { + public PacketBeeLogicActive(IBeeHousing tile) { super(PacketIdClient.BEE_LOGIC_ACTIVE, tile.getCoordinates()); this.beekeepingLogic = (BeekeepingLogic) tile.getBeekeepingLogic(); } diff --git a/src/main/java/forestry/apiculture/network/PacketBeeLogicActiveEntity.java b/src/main/java/forestry/apiculture/network/PacketBeeLogicActiveEntity.java new file mode 100644 index 000000000..1d533cc5b --- /dev/null +++ b/src/main/java/forestry/apiculture/network/PacketBeeLogicActiveEntity.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; + +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.apiculture.BeekeepingLogic; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.PacketEntityUpdate; +import forestry.core.network.PacketIdClient; +import forestry.core.proxy.Proxies; + +public class PacketBeeLogicActiveEntity extends PacketEntityUpdate implements IForestryPacketClient { + private BeekeepingLogic beekeepingLogic; + + public PacketBeeLogicActiveEntity() { + } + + public PacketBeeLogicActiveEntity(IBeeHousing housing, Entity entity) { + super(PacketIdClient.BEE_LOGIC_ACTIVE_ENTITY, entity); + this.beekeepingLogic = (BeekeepingLogic) housing.getBeekeepingLogic(); + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + beekeepingLogic.writeData(data); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { + Entity entity = getTarget(Proxies.common.getRenderWorld()); + if (entity instanceof IBeeHousing) { + IBeeHousing beeHousing = (IBeeHousing) entity; + IBeekeepingLogic beekeepingLogic = beeHousing.getBeekeepingLogic(); + if (beekeepingLogic instanceof BeekeepingLogic) { + ((BeekeepingLogic) beekeepingLogic).readData(data); + } + } + } +} diff --git a/src/main/java/forestry/apiculture/network/PacketBeeLogicEntityRequest.java b/src/main/java/forestry/apiculture/network/PacketBeeLogicEntityRequest.java new file mode 100644 index 000000000..3ee25ec67 --- /dev/null +++ b/src/main/java/forestry/apiculture/network/PacketBeeLogicEntityRequest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; + +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.PacketEntityUpdate; +import forestry.core.network.PacketIdServer; + +public class PacketBeeLogicEntityRequest extends PacketEntityUpdate implements IForestryPacketServer { + + public PacketBeeLogicEntityRequest() { + } + + public PacketBeeLogicEntityRequest(Entity entity) { + super(PacketIdServer.BEE_LOGIC_ACTIVE_ENTITY_REQUEST, entity); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException { + Entity entity = getTarget(player.worldObj); + if (entity instanceof IBeeHousing) { + IBeeHousing beeHousing = (IBeeHousing) entity; + IBeekeepingLogic beekeepingLogic = beeHousing.getBeekeepingLogic(); + if (beekeepingLogic != null) { + beekeepingLogic.syncToClient(player); + } + } + } + +} diff --git a/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java b/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java index 3cee80d94..cff88e343 100644 --- a/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java +++ b/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java @@ -10,10 +10,11 @@ ******************************************************************************/ package forestry.apiculture.tiles; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; +import java.io.IOException; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.Packet; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -25,12 +26,16 @@ import forestry.api.apiculture.IBeekeepingLogic; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.apiculture.BeeHousingInventory; +import forestry.apiculture.gui.IGuiBeeHousingInventory; import forestry.core.config.Config; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IStreamableGui; import forestry.core.proxy.Proxies; import forestry.core.tiles.IClimatised; import forestry.core.tiles.TileBase; -public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHousing, IClimatised { +public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHousing, IClimatised, IGuiBeeHousingInventory, IStreamableGui { private final IBeekeepingLogic beeLogic; private BiomeGenBase cachedBiome; @@ -94,22 +99,26 @@ public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHou beeLogic.doBeeFX(); if (updateOnInterval(50)) { - float fxX = xCoord + 0.5F; - float fxY = yCoord + 0.25F; - float fxZ = zCoord + 0.5F; - float distanceFromCenter = 0.6F; - float leftRightSpreadFromCenter = distanceFromCenter * (worldObj.rand.nextFloat() - 0.5F); - float upSpread = (worldObj.rand.nextFloat() * 6F) / 16F; - fxY += upSpread; - - Proxies.render.addEntitySwarmFX(worldObj, (fxX - distanceFromCenter), fxY, (fxZ + leftRightSpreadFromCenter)); - Proxies.render.addEntitySwarmFX(worldObj, (fxX + distanceFromCenter), fxY, (fxZ + leftRightSpreadFromCenter)); - Proxies.render.addEntitySwarmFX(worldObj, (fxX + leftRightSpreadFromCenter), fxY, (fxZ - distanceFromCenter)); - Proxies.render.addEntitySwarmFX(worldObj, (fxX + leftRightSpreadFromCenter), fxY, (fxZ + distanceFromCenter)); + doPollenFX(worldObj, xCoord, yCoord, zCoord); } } } + public static void doPollenFX(World world, double xCoord, double yCoord, double zCoord) { + double fxX = xCoord + 0.5F; + double fxY = yCoord + 0.25F; + double fxZ = zCoord + 0.5F; + float distanceFromCenter = 0.6F; + float leftRightSpreadFromCenter = distanceFromCenter * (world.rand.nextFloat() - 0.5F); + float upSpread = (world.rand.nextFloat() * 6F) / 16F; + fxY += upSpread; + + Proxies.render.addEntitySwarmFX(world, (fxX - distanceFromCenter), fxY, (fxZ + leftRightSpreadFromCenter)); + Proxies.render.addEntitySwarmFX(world, (fxX + distanceFromCenter), fxY, (fxZ + leftRightSpreadFromCenter)); + Proxies.render.addEntitySwarmFX(world, (fxX + leftRightSpreadFromCenter), fxY, (fxZ - distanceFromCenter)); + Proxies.render.addEntitySwarmFX(world, (fxX + leftRightSpreadFromCenter), fxY, (fxZ + distanceFromCenter)); + } + @Override public void updateServerSide() { if (beeLogic.canWork()) { @@ -117,24 +126,19 @@ public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHou } } - /** - * Returns scaled queen health or breeding progress - */ + @Override public int getHealthScaled(int i) { return (breedingProgressPercent * i) / 100; } - /* SMP */ - public void getGUINetworkData(int i, int j) { - switch (i) { - case 0: - breedingProgressPercent = j; - break; - } + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + data.writeVarInt(beeLogic.getBeeProgressPercent()); } - public void sendGUINetworkData(Container container, ICrafting iCrafting) { - iCrafting.sendProgressBarUpdate(container, 0, beeLogic.getBeeProgressPercent()); + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + breedingProgressPercent = data.readVarInt(); } // / IBEEHOUSING @@ -166,6 +170,11 @@ public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHou return worldObj; } + @Override + public Vec3 getBeeFXCoordinates() { + return Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); + } + public static class TileBeeHousingInventory extends BeeHousingInventory { private final TileAbstractBeeHousing tile; diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java index 0453b09a0..8dcd01b4e 100755 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java @@ -78,11 +78,6 @@ public class ItemTreealyzer extends ItemAlyzer { } // / IHINTSOURCE - @Override - public boolean hasHints() { - return Config.hints.get("treealyzer") != null && Config.hints.get("treealyzer").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("treealyzer"); diff --git a/src/main/java/forestry/core/GuiHandler.java b/src/main/java/forestry/core/GuiHandler.java index 3bf390bb8..143589242 100755 --- a/src/main/java/forestry/core/GuiHandler.java +++ b/src/main/java/forestry/core/GuiHandler.java @@ -26,6 +26,7 @@ import forestry.core.gui.GuiEscritoire; import forestry.core.network.GuiId; import forestry.core.tiles.TileAnalyzer; import forestry.core.tiles.TileEscritoire; +import forestry.core.tiles.TileUtil; import forestry.plugins.PluginManager; public class GuiHandler extends GuiHandlerBase { @@ -38,10 +39,10 @@ public class GuiHandler extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AnalyzerGUI: - return new GuiAnalyzer(player.inventory, getTile(world, x, y, z, player, TileAnalyzer.class)); + return new GuiAnalyzer(player.inventory, TileUtil.getTile(world, x, y, z, TileAnalyzer.class)); case NaturalistBenchGUI: - return new GuiEscritoire(player, getTile(world, x, y, z, player, TileEscritoire.class)); + return new GuiEscritoire(player, TileUtil.getTile(world, x, y, z, TileEscritoire.class)); case SolderingIronGUI: ItemStack equipped = player.getCurrentEquippedItem(); @@ -73,10 +74,10 @@ public class GuiHandler extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AnalyzerGUI: - return new ContainerAnalyzer(player.inventory, getTile(world, x, y, z, player, TileAnalyzer.class)); + return new ContainerAnalyzer(player.inventory, TileUtil.getTile(world, x, y, z, TileAnalyzer.class)); case NaturalistBenchGUI: - return new ContainerEscritoire(player, getTile(world, x, y, z, player, TileEscritoire.class)); + return new ContainerEscritoire(player, TileUtil.getTile(world, x, y, z, TileEscritoire.class)); case SolderingIronGUI: ItemStack equipped = player.getCurrentEquippedItem(); diff --git a/src/main/java/forestry/core/GuiHandlerBase.java b/src/main/java/forestry/core/GuiHandlerBase.java index f7b258255..bf0802a91 100755 --- a/src/main/java/forestry/core/GuiHandlerBase.java +++ b/src/main/java/forestry/core/GuiHandlerBase.java @@ -11,7 +11,6 @@ package forestry.core; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; @@ -19,33 +18,19 @@ import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.genetics.ISpeciesRoot; import forestry.core.gui.ContainerNaturalistInventory; import forestry.core.gui.GuiNaturalistInventory; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketGuiUpdate; -import forestry.core.proxy.Proxies; import forestry.core.tiles.TileNaturalistChest; import forestry.core.tiles.TileUtil; public abstract class GuiHandlerBase implements IGuiHandler { - protected static T getTile(World world, int x, int y, int z, EntityPlayer player, Class tileClass) { - T tileForestry = TileUtil.getTile(world, x, y, z, tileClass); - - if (tileForestry instanceof IStreamableGui && !world.isRemote) { - PacketGuiUpdate packet = new PacketGuiUpdate((IStreamableGui) tileForestry); - Proxies.net.sendToPlayer(packet, player); - } - - return tileForestry; - } - protected GuiNaturalistInventory getNaturalistChestGui(ISpeciesRoot speciesRoot, EntityPlayer player, World world, int x, int y, int z, int page) { - TileNaturalistChest tile = getTile(world, x, y, z, player, TileNaturalistChest.class); + TileNaturalistChest tile = TileUtil.getTile(world, x, y, z, TileNaturalistChest.class); return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistInventory(player.inventory, tile, page), tile, page, 5); } protected ContainerNaturalistInventory getNaturalistChestContainer(ISpeciesRoot speciesRoot, EntityPlayer player, World world, int x, int y, int z, int page) { speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); - return new ContainerNaturalistInventory(player.inventory, getTile(world, x, y, z, player, TileNaturalistChest.class), page); + return new ContainerNaturalistInventory(player.inventory, TileUtil.getTile(world, x, y, z, TileNaturalistChest.class), page); } public static int encodeGuiData(int guiId, int data) { diff --git a/src/main/java/forestry/core/access/AccessHandler.java b/src/main/java/forestry/core/access/AccessHandler.java index 5a5ca8762..475ce8de7 100644 --- a/src/main/java/forestry/core/access/AccessHandler.java +++ b/src/main/java/forestry/core/access/AccessHandler.java @@ -11,37 +11,56 @@ package forestry.core.access; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; +import net.minecraft.world.World; import com.mojang.authlib.GameProfile; -import forestry.api.core.INBTTagable; import forestry.core.config.Config; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; -import forestry.core.network.IStreamable; import forestry.core.network.PacketAccessSwitch; +import forestry.core.network.PacketAccessSwitchEntity; import forestry.core.proxy.Proxies; -import forestry.core.tiles.IRestrictedAccessTile; +import forestry.core.tiles.ILocatable; import forestry.core.utils.PlayerUtil; -public final class AccessHandler implements IAccessHandler, IStreamable, INBTTagable { - private final IRestrictedAccessTile tile; +public final class AccessHandler implements IAccessHandler { + private final IRestrictedAccess accessListener; + private final List accessOwnerListeners = new ArrayList<>(); + private final Object target; private GameProfile owner = null; private EnumAccess access = EnumAccess.SHARED; - public AccessHandler(IRestrictedAccessTile tile) { - this.tile = tile; + public AccessHandler(T tile) { + this.accessListener = tile; + this.target = tile; + } + + public AccessHandler(T entity) { + this.accessListener = entity; + this.target = entity; + } + + public void addOwnerListener(IAccessOwnerListener accessListener) { + accessOwnerListeners.add(accessListener); + } + + public void removeOwnerListener(IAccessOwnerListener accessListener) { + accessOwnerListeners.remove(accessListener); } @Override public final boolean allowsRemoval(EntityPlayer player) { - return !Config.enablePermissions || getAccessType() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player); + return !Config.enablePermissions || getAccess() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player); } @Override @@ -51,7 +70,7 @@ public final class AccessHandler implements IAccessHandler, IStreamable, INBTTag @Override public final boolean allowsViewing(EntityPlayer player) { - return allowsAlteration(player) || getAccessType() == EnumAccess.VIEWABLE; + return allowsAlteration(player) || getAccess() == EnumAccess.VIEWABLE; } @Override @@ -60,7 +79,7 @@ public final class AccessHandler implements IAccessHandler, IStreamable, INBTTag } @Override - public EnumAccess getAccessType() { + public EnumAccess getAccess() { return access; } @@ -77,6 +96,9 @@ public final class AccessHandler implements IAccessHandler, IStreamable, INBTTag @Override public void setOwner(GameProfile owner) { this.owner = owner; + for (IAccessOwnerListener listener : accessOwnerListeners) { + listener.onOwnerSet(owner); + } } @Override @@ -85,24 +107,37 @@ public final class AccessHandler implements IAccessHandler, IStreamable, INBTTag } @Override - public boolean switchAccessRule(EntityPlayer player) { + public boolean switchAccess(EntityPlayer player) { if (!isOwner(player)) { return false; } - EnumAccess oldAccess = access; int ordinal = (access.ordinal() + 1) % EnumAccess.values().length; - access = EnumAccess.values()[ordinal]; - - if (player.worldObj.isRemote) { - Proxies.net.sendToServer(new PacketAccessSwitch(tile.getCoordinates())); - } else { - tile.onSwitchAccess(oldAccess, access); - } + EnumAccess newAccess = EnumAccess.values()[ordinal]; + setAccess(player.worldObj, newAccess); return true; } + private void setAccess(World world, EnumAccess access) { + EnumAccess oldAccess = this.access; + if (oldAccess == access) { + return; + } + + this.access = access; + + if (world.isRemote) { + if (target instanceof ILocatable) { + Proxies.net.sendToServer(new PacketAccessSwitch((ILocatable) target)); + } else if (target instanceof Entity) { + Proxies.net.sendToServer(new PacketAccessSwitchEntity((Entity) target)); + } + } else { + accessListener.onSwitchAccess(oldAccess, access); + } + } + @Override public void writeData(DataOutputStreamForestry data) throws IOException { if (owner == null) { @@ -120,7 +155,8 @@ public final class AccessHandler implements IAccessHandler, IStreamable, INBTTag byte accessOrdinal = data.readByte(); if (accessOrdinal >= 0) { access = EnumAccess.values()[accessOrdinal]; - owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF()); + GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF()); + setOwner(owner); } } diff --git a/src/main/java/forestry/core/access/FakeAccessHandler.java b/src/main/java/forestry/core/access/FakeAccessHandler.java index 9648b0142..511cf3c0f 100644 --- a/src/main/java/forestry/core/access/FakeAccessHandler.java +++ b/src/main/java/forestry/core/access/FakeAccessHandler.java @@ -10,10 +10,16 @@ ******************************************************************************/ package forestry.core.access; +import java.io.IOException; + import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; import com.mojang.authlib.GameProfile; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; + public class FakeAccessHandler implements IAccessHandler { private static FakeAccessHandler instance; @@ -29,12 +35,12 @@ public class FakeAccessHandler implements IAccessHandler { } @Override - public boolean switchAccessRule(EntityPlayer player) { + public boolean switchAccess(EntityPlayer player) { return false; } @Override - public EnumAccess getAccessType() { + public EnumAccess getAccess() { return EnumAccess.SHARED; } @@ -58,6 +64,16 @@ public class FakeAccessHandler implements IAccessHandler { return true; } + @Override + public void addOwnerListener(IAccessOwnerListener accessListener) { + + } + + @Override + public void removeOwnerListener(IAccessOwnerListener accessListener) { + + } + @Override public boolean isOwned() { return false; @@ -77,4 +93,24 @@ public class FakeAccessHandler implements IAccessHandler { public boolean isOwner(EntityPlayer player) { return true; } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + + } + + @Override + public void writeData(DataOutputStreamForestry data) throws IOException { + + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + + } } diff --git a/src/main/java/forestry/core/access/IAccessHandler.java b/src/main/java/forestry/core/access/IAccessHandler.java index b155a9334..4b0195f0d 100644 --- a/src/main/java/forestry/core/access/IAccessHandler.java +++ b/src/main/java/forestry/core/access/IAccessHandler.java @@ -12,11 +12,14 @@ package forestry.core.access; import net.minecraft.entity.player.EntityPlayer; -public interface IAccessHandler extends IOwnable { +import forestry.api.core.INBTTagable; +import forestry.core.network.IStreamable; - boolean switchAccessRule(EntityPlayer player); +public interface IAccessHandler extends IOwnable, IStreamable, INBTTagable { - EnumAccess getAccessType(); + boolean switchAccess(EntityPlayer player); + + EnumAccess getAccess(); boolean allowsRemoval(EntityPlayer player); @@ -26,4 +29,8 @@ public interface IAccessHandler extends IOwnable { boolean allowsPipeConnections(); + void addOwnerListener(IAccessOwnerListener accessListener); + + void removeOwnerListener(IAccessOwnerListener accessListener); + } diff --git a/src/main/java/forestry/core/access/IAccessOwnerListener.java b/src/main/java/forestry/core/access/IAccessOwnerListener.java new file mode 100644 index 000000000..cdd0ec89d --- /dev/null +++ b/src/main/java/forestry/core/access/IAccessOwnerListener.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.access; + +import com.mojang.authlib.GameProfile; + +public interface IAccessOwnerListener { + void onOwnerSet(GameProfile gameProfile); +} diff --git a/src/main/java/forestry/core/tiles/IRestrictedAccessTile.java b/src/main/java/forestry/core/access/IRestrictedAccess.java similarity index 67% rename from src/main/java/forestry/core/tiles/IRestrictedAccessTile.java rename to src/main/java/forestry/core/access/IRestrictedAccess.java index 036d22a49..248444d0d 100644 --- a/src/main/java/forestry/core/tiles/IRestrictedAccessTile.java +++ b/src/main/java/forestry/core/access/IRestrictedAccess.java @@ -8,18 +8,9 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.tiles; +package forestry.core.access; -import net.minecraft.util.ChunkCoordinates; - -import forestry.core.access.EnumAccess; -import forestry.core.access.IAccessHandler; -import forestry.core.network.IStreamableGui; - -public interface IRestrictedAccessTile extends IStreamableGui { +public interface IRestrictedAccess { IAccessHandler getAccessHandler(); - - ChunkCoordinates getCoordinates(); - void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess); } diff --git a/src/main/java/forestry/core/blocks/BlockForestry.java b/src/main/java/forestry/core/blocks/BlockForestry.java index da81f2bd4..3fe80f8d1 100644 --- a/src/main/java/forestry/core/blocks/BlockForestry.java +++ b/src/main/java/forestry/core/blocks/BlockForestry.java @@ -25,7 +25,7 @@ import com.mojang.authlib.GameProfile; import forestry.core.CreativeTabForestry; import forestry.core.access.IOwnable; -import forestry.core.tiles.IRestrictedAccessTile; +import forestry.core.access.IRestrictedAccess; import forestry.core.tiles.TileForestry; import forestry.core.utils.Log; @@ -41,8 +41,8 @@ public abstract class BlockForestry extends BlockContainer { public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); - if (tile instanceof IRestrictedAccessTile) { - IRestrictedAccessTile restrictedAccessTile = (IRestrictedAccessTile) tile; + if (tile instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile; if (!restrictedAccessTile.getAccessHandler().allowsRemoval(player)) { return false; } @@ -63,8 +63,8 @@ public abstract class BlockForestry extends BlockContainer { IOwnable ownable; - if (tile instanceof IRestrictedAccessTile) { - ownable = ((IRestrictedAccessTile) tile).getAccessHandler(); + if (tile instanceof IRestrictedAccess) { + ownable = ((IRestrictedAccess) tile).getAccessHandler(); } else if (tile instanceof IOwnable) { ownable = (IOwnable) tile; } else { diff --git a/src/main/java/forestry/core/config/ForestryItem.java b/src/main/java/forestry/core/config/ForestryItem.java index 53c92c746..ae3f27caf 100755 --- a/src/main/java/forestry/core/config/ForestryItem.java +++ b/src/main/java/forestry/core/config/ForestryItem.java @@ -120,6 +120,7 @@ public enum ForestryItem { frameUntreated, frameImpregnated, frameProven, + minecartBeehouse, // Trees sapling, pollenFertile, diff --git a/src/main/java/forestry/core/gui/ContainerEntity.java b/src/main/java/forestry/core/gui/ContainerEntity.java new file mode 100644 index 000000000..af1d91bf9 --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerEntity.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.gui; + +import com.google.common.collect.ImmutableSet; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; + +import forestry.api.core.IErrorLogicSource; +import forestry.api.core.IErrorState; +import forestry.core.access.EnumAccess; +import forestry.core.access.FakeAccessHandler; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.PacketAccessUpdateEntity; +import forestry.core.network.PacketErrorUpdateEntity; + +public class ContainerEntity extends ContainerForestry { + protected final T entity; + private final IAccessHandler accessHandler; + + protected ContainerEntity(T entity) { + this.entity = entity; + + if (entity instanceof IRestrictedAccess) { + accessHandler = ((IRestrictedAccess) entity).getAccessHandler(); + } else { + accessHandler = FakeAccessHandler.getInstance(); + } + } + + protected ContainerEntity(T entity, InventoryPlayer playerInventory, int xInv, int yInv) { + this(entity); + addPlayerInventory(playerInventory, xInv, yInv); + } + + @Override + protected final boolean canAccess(EntityPlayer player) { + return player != null && accessHandler.allowsAlteration(player); + } + + @Override + public final boolean canInteractWith(EntityPlayer entityplayer) { + return entity.isUseableByPlayer(entityplayer) && accessHandler.allowsViewing(entityplayer); + } + + private ImmutableSet previousErrorStates; + private EnumAccess previousAccess; + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + if (entity instanceof IErrorLogicSource) { + IErrorLogicSource errorLogicSource = (IErrorLogicSource) entity; + ImmutableSet errorStates = errorLogicSource.getErrorLogic().getErrorStates(); + + if ((previousErrorStates == null) || !errorStates.equals(previousErrorStates)) { + PacketErrorUpdateEntity packet = new PacketErrorUpdateEntity(entity, errorLogicSource); + sendPacketToCrafters(packet); + } + + previousErrorStates = errorStates; + } + + if (entity instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccess = (IRestrictedAccess) entity; + IAccessHandler accessHandler = restrictedAccess.getAccessHandler(); + EnumAccess access = accessHandler.getAccess(); + if (access != previousAccess) { + IForestryPacketClient packet = new PacketAccessUpdateEntity(restrictedAccess, entity); + sendPacketToCrafters(packet); + + previousAccess = access; + } + } + } +} diff --git a/src/main/java/forestry/core/gui/ContainerForestry.java b/src/main/java/forestry/core/gui/ContainerForestry.java index 77500371a..f09d09346 100644 --- a/src/main/java/forestry/core/gui/ContainerForestry.java +++ b/src/main/java/forestry/core/gui/ContainerForestry.java @@ -40,6 +40,11 @@ public abstract class ContainerForestry extends Container { addSlotToContainer(new Slot(playerInventory, slot, x, y)); } + @Override + public Slot addSlotToContainer(Slot p_75146_1_) { + return super.addSlotToContainer(p_75146_1_); + } + @Override public ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) { if (!canAccess(player)) { diff --git a/src/main/java/forestry/core/gui/ContainerTile.java b/src/main/java/forestry/core/gui/ContainerTile.java index 5de1f4a79..405d7bc50 100644 --- a/src/main/java/forestry/core/gui/ContainerTile.java +++ b/src/main/java/forestry/core/gui/ContainerTile.java @@ -21,11 +21,13 @@ import forestry.api.core.IErrorState; import forestry.core.access.EnumAccess; import forestry.core.access.FakeAccessHandler; import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.PacketAccessUpdate; import forestry.core.network.PacketErrorUpdate; import forestry.core.network.PacketGuiEnergy; import forestry.core.network.PacketGuiUpdate; import forestry.core.tiles.IPowerHandler; -import forestry.core.tiles.IRestrictedAccessTile; import forestry.core.tiles.TilePowered; import forestry.core.tiles.TileUtil; import forestry.energy.EnergyManager; @@ -38,8 +40,8 @@ public abstract class ContainerTile extends ContainerFores protected ContainerTile(T tile) { this.tile = tile; - if (tile instanceof IRestrictedAccessTile) { - accessHandler = ((IRestrictedAccessTile) tile).getAccessHandler(); + if (tile instanceof IRestrictedAccess) { + accessHandler = ((IRestrictedAccess) tile).getAccessHandler(); } else { accessHandler = FakeAccessHandler.getInstance(); } @@ -75,7 +77,7 @@ public abstract class ContainerTile extends ContainerFores IErrorLogicSource errorLogicSource = (IErrorLogicSource) tile; ImmutableSet errorStates = errorLogicSource.getErrorLogic().getErrorStates(); - if ((previousErrorStates != null) && !errorStates.equals(previousErrorStates)) { + if ((previousErrorStates == null) || !errorStates.equals(previousErrorStates)) { PacketErrorUpdate packet = new PacketErrorUpdate(tile, errorLogicSource); sendPacketToCrafters(packet); } @@ -94,42 +96,38 @@ public abstract class ContainerTile extends ContainerFores } } - boolean guiUpdated = false; - - if (!guiUpdated && tile instanceof IRestrictedAccessTile) { - IRestrictedAccessTile restrictedAccessTile = (IRestrictedAccessTile) tile; - IAccessHandler accessHandler = restrictedAccessTile.getAccessHandler(); - EnumAccess access = accessHandler.getAccessType(); + if (tile instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccess = (IRestrictedAccess) tile; + IAccessHandler accessHandler = restrictedAccess.getAccessHandler(); + EnumAccess access = accessHandler.getAccess(); if (access != previousAccess) { - PacketGuiUpdate packet = new PacketGuiUpdate(restrictedAccessTile); + IForestryPacketClient packet = new PacketAccessUpdate(restrictedAccess, tile); sendPacketToCrafters(packet); previousAccess = access; - guiUpdated = true; } } - if (!guiUpdated && tile instanceof TilePowered) { - TilePowered tilePowered = (TilePowered) tile; + if (tile instanceof TilePowered) { + boolean guiNeedsUpdate = false; - boolean changed = false; + TilePowered tilePowered = (TilePowered) tile; int workCounter = tilePowered.getWorkCounter(); if (workCounter != previousWorkCounter) { - changed = true; + guiNeedsUpdate = true; previousWorkCounter = workCounter; } int ticksPerWorkCycle = tilePowered.getTicksPerWorkCycle(); if (ticksPerWorkCycle != previousTicksPerWorkCycle) { - changed = true; + guiNeedsUpdate = true; previousTicksPerWorkCycle = ticksPerWorkCycle; } - if (changed) { + if (guiNeedsUpdate) { PacketGuiUpdate packet = new PacketGuiUpdate(tilePowered); sendPacketToCrafters(packet); - guiUpdated = true; } } } diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 6e6287dbf..bdd0e1200 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -36,6 +36,7 @@ import org.lwjgl.opengl.GL12; import forestry.api.core.IErrorLogicSource; import forestry.api.core.IErrorSource; +import forestry.core.access.IRestrictedAccess; import forestry.core.config.Config; import forestry.core.gui.ledgers.ClimateLedger; import forestry.core.gui.ledgers.HintLedger; @@ -51,7 +52,6 @@ import forestry.core.proxy.Proxies; import forestry.core.render.FontColour; import forestry.core.tiles.IClimatised; import forestry.core.tiles.IPowerHandler; -import forestry.core.tiles.TileForestry; import codechicken.nei.VisiblityData; import codechicken.nei.api.INEIGuiHandler; @@ -110,15 +110,25 @@ public abstract class GuiForestry ext ledgerManager.add(new PowerLedger(ledgerManager, (IPowerHandler) inventory)); } - if (Config.enableHints && inventory instanceof IHintSource && ((IHintSource) inventory).hasHints()) { - ledgerManager.add(new HintLedger(ledgerManager, (IHintSource) inventory)); + if (Config.enableHints && inventory instanceof IHintSource) { + IHintSource hintSource = (IHintSource) inventory; + String[] hints = hintSource.getHints(); + if (hints != null && hints.length > 0) { + ledgerManager.add(new HintLedger(ledgerManager, hintSource)); + } } - if (inventory instanceof TileForestry) { - ledgerManager.add(new OwnerLedger(ledgerManager, (TileForestry) inventory)); + if (inventory instanceof IRestrictedAccess) { + ledgerManager.add(new OwnerLedger(ledgerManager, (IRestrictedAccess) inventory)); } } + @Override + public void onGuiClosed() { + super.onGuiClosed(); + ledgerManager.onGuiClosed(); + } + /* TEXT HELPER FUNCTIONS */ protected int column0; protected int column1; diff --git a/src/main/java/forestry/core/gui/GuiForestryTitled.java b/src/main/java/forestry/core/gui/GuiForestryTitled.java index 569877981..d27fd6794 100644 --- a/src/main/java/forestry/core/gui/GuiForestryTitled.java +++ b/src/main/java/forestry/core/gui/GuiForestryTitled.java @@ -12,9 +12,9 @@ package forestry.core.gui; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; +import net.minecraft.util.StatCollector; import forestry.core.tiles.ITitled; -import forestry.core.utils.StringUtil; public abstract class GuiForestryTitled extends GuiForestry { @@ -24,7 +24,7 @@ public abstract class GuiForestryTitled= maxWidth; } + public void onGuiClosed() { + + } + protected void drawBackground(int x, int y) { float colorR = (overlayColor >> 16 & 255) / 255.0F; diff --git a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java index f0d9fa0cb..45da781fa 100644 --- a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java +++ b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java @@ -61,6 +61,12 @@ public class LedgerManager { } } + public void onGuiClosed() { + for (Ledger ledger : ledgers) { + ledger.onGuiClosed(); + } + } + /** * Inserts a ledger into the next-to-last position. */ diff --git a/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java index 74ba5db1f..b2b8ba0f9 100644 --- a/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java @@ -16,34 +16,30 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.IIcon; +import com.mojang.authlib.GameProfile; + import forestry.core.access.EnumAccess; import forestry.core.access.IAccessHandler; +import forestry.core.access.IAccessOwnerListener; +import forestry.core.access.IRestrictedAccess; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.tiles.IRestrictedAccessTile; import forestry.core.utils.PlayerUtil; import forestry.core.utils.StringUtil; /** * Ledger displaying ownership information */ -public class OwnerLedger extends Ledger { +public class OwnerLedger extends Ledger implements IAccessOwnerListener { private final IAccessHandler accessHandler; - public OwnerLedger(LedgerManager manager, IRestrictedAccessTile tile) { + public OwnerLedger(LedgerManager manager, IRestrictedAccess tile) { super(manager, "owner"); this.accessHandler = tile.getAccessHandler(); - - Minecraft minecraft = Proxies.common.getClientInstance(); - boolean playerIsOwner = accessHandler.isOwner(minecraft.thePlayer); - - if (playerIsOwner) { - maxHeight = 60; - } else { - maxHeight = 36; - } + accessHandler.addOwnerListener(this); + onOwnerSet(accessHandler.getOwner()); } private boolean isAccessButton(int mouseX, int mouseY) { @@ -65,7 +61,7 @@ public class OwnerLedger extends Ledger { drawBackground(x, y); // Draw icon - EnumAccess accessType = accessHandler.getAccessType(); + EnumAccess accessType = accessHandler.getAccess(); IIcon accessIcon = TextureManager.getInstance().getDefault("misc/access." + accessType.toString().toLowerCase(Locale.ENGLISH)); drawIcon(accessIcon, x + 3, y + 4); @@ -100,9 +96,26 @@ public class OwnerLedger extends Ledger { Minecraft minecraft = Proxies.common.getClientInstance(); EntityPlayer player = minecraft.thePlayer; - return accessHandler.switchAccessRule(player); + return accessHandler.switchAccess(player); } return false; } + + @Override + public void onOwnerSet(GameProfile gameProfile) { + Minecraft minecraft = Proxies.common.getClientInstance(); + boolean playerIsOwner = PlayerUtil.isSameGameProfile(minecraft.thePlayer.getGameProfile(), gameProfile); + if (playerIsOwner) { + maxHeight = 60; + } else { + maxHeight = 36; + } + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + accessHandler.removeOwnerListener(this); + } } diff --git a/src/main/java/forestry/core/inventory/InventoryAdapter.java b/src/main/java/forestry/core/inventory/InventoryAdapter.java index 80969c6e1..d07d10d6d 100755 --- a/src/main/java/forestry/core/inventory/InventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/InventoryAdapter.java @@ -22,6 +22,7 @@ import forestry.core.config.Constants; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; +import forestry.core.utils.InventoryUtil; /** * With permission from Krapht. @@ -184,31 +185,12 @@ public class InventoryAdapter implements IInventoryAdapter, IStreamable { /* SAVING & LOADING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { - if (!nbttagcompound.hasKey(inventory.getInventoryName())) { - return; - } - - NBTTagList nbttaglist = nbttagcompound.getTagList(inventory.getInventoryName(), 10); - - for (int j = 0; j < nbttaglist.tagCount(); ++j) { - NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); - int index = nbttagcompound2.getByte("Slot"); - inventory.setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(nbttagcompound2)); - } + InventoryUtil.readFromNBT(this, nbttagcompound); } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (inventory.getStackInSlot(i) != null) { - NBTTagCompound nbttagcompound2 = new NBTTagCompound(); - nbttagcompound2.setByte("Slot", (byte) i); - inventory.getStackInSlot(i).writeToNBT(nbttagcompound2); - nbttaglist.appendTag(nbttagcompound2); - } - } - nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist); + InventoryUtil.writeToNBT(this, nbttagcompound); } @Override diff --git a/src/main/java/forestry/core/inventory/InventoryPlain.java b/src/main/java/forestry/core/inventory/InventoryPlain.java index 6154c4259..f9605e759 100644 --- a/src/main/java/forestry/core/inventory/InventoryPlain.java +++ b/src/main/java/forestry/core/inventory/InventoryPlain.java @@ -13,8 +13,13 @@ package forestry.core.inventory; 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; -public class InventoryPlain implements IInventory { +import forestry.api.core.INBTTagable; +import forestry.core.utils.InventoryUtil; + +public class InventoryPlain implements IInventory, INBTTagable { private final ItemStack[] contents; private final String name; @@ -114,4 +119,15 @@ public class InventoryPlain implements IInventory { @Override public void closeInventory() { } + + /* INBTagable */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + InventoryUtil.readFromNBT(this, nbttagcompound); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + InventoryUtil.writeToNBT(this, nbttagcompound); + } } diff --git a/src/main/java/forestry/core/inventory/TileInventoryAdapter.java b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java index 7d3668fed..882783065 100755 --- a/src/main/java/forestry/core/inventory/TileInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java @@ -13,9 +13,9 @@ package forestry.core.inventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import forestry.core.tiles.IRestrictedAccessTile; +import forestry.core.access.IRestrictedAccess; -public class TileInventoryAdapter extends InventoryAdapterRestricted { +public class TileInventoryAdapter extends InventoryAdapterRestricted { protected final T tile; diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index abe53dc19..18231289e 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -3,7 +3,6 @@ package forestry.core.multiblock; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; -import java.io.IOException; import java.util.HashSet; import java.util.LinkedList; import java.util.Random; @@ -27,11 +26,10 @@ import forestry.api.core.IErrorLogicSource; import forestry.core.access.AccessHandler; import forestry.core.access.IAccessHandler; import forestry.core.access.IOwnable; +import forestry.core.access.IRestrictedAccess; import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.network.DataInputStreamForestry; -import forestry.core.network.DataOutputStreamForestry; -import forestry.core.tiles.IRestrictedAccessTile; +import forestry.core.tiles.ILocatable; import forestry.core.utils.Log; import forestry.core.utils.StringUtil; @@ -41,7 +39,7 @@ import forestry.core.utils.StringUtil; * * Subordinate TileEntities implement the IMultiblockPart class and, generally, should not have an update() loop. */ -public abstract class MultiblockControllerBase implements ISidedInventory, IRestrictedAccessTile, IErrorLogicSource { +public abstract class MultiblockControllerBase implements ISidedInventory, IRestrictedAccess, IErrorLogicSource, ILocatable { public static final short DIMENSION_UNBOUNDED = -1; // Multiblock stuff - do not mess with @@ -224,8 +222,8 @@ public abstract class MultiblockControllerBase implements ISidedInventory, IRest Multiset owners = HashMultiset.create(); for (IMultiblockPart part : connectedParts) { - if (part instanceof IRestrictedAccessTile) { - IAccessHandler accessHandler = ((IRestrictedAccessTile) part).getAccessHandler(); + if (part instanceof IRestrictedAccess) { + IAccessHandler accessHandler = ((IRestrictedAccess) part).getAccessHandler(); GameProfile owner = accessHandler.getOwner(); if (owner != null) { owners.add(owner); @@ -1115,16 +1113,4 @@ public abstract class MultiblockControllerBase implements ISidedInventory, IRest public final boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) { return getInternalInventory().canExtractItem(slotIndex, itemStack, side); } - - @Override - public void writeGuiData(DataOutputStreamForestry data) throws IOException { - accessHandler.writeData(data); - errorLogic.writeData(data); - } - - @Override - public void readGuiData(DataInputStreamForestry data) throws IOException { - accessHandler.readData(data); - errorLogic.readData(data); - } } diff --git a/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java b/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java index 4b66b9234..42964e59a 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java @@ -14,6 +14,8 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import com.mojang.authlib.GameProfile; @@ -23,6 +25,7 @@ import forestry.core.config.Constants; import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.tiles.IFilterSlotDelegate; +import forestry.core.tiles.ILocatable; import forestry.core.utils.Log; import forestry.core.utils.PlayerUtil; @@ -30,7 +33,7 @@ import forestry.core.utils.PlayerUtil; * Base logic class for Multiblock-connected tile entities. Most multiblock machines * should derive from this and implement their game logic in certain abstract methods. */ -public abstract class MultiblockTileEntityBase extends IMultiblockPart implements ISidedInventory, IFilterSlotDelegate, IOwnable { +public abstract class MultiblockTileEntityBase extends IMultiblockPart implements ISidedInventory, IFilterSlotDelegate, IOwnable, ILocatable { private MultiblockControllerBase controller; private boolean visited; @@ -517,4 +520,15 @@ public abstract class MultiblockTileEntityBase extends IMultiblockPart implement public void openGui(EntityPlayer player) { } + + /* ILocatable */ + @Override + public ChunkCoordinates getCoordinates() { + return getMultiblockController().getCoordinates(); + } + + @Override + public final World getWorld() { + return worldObj; + } } diff --git a/src/main/java/forestry/core/network/ForestryPacket.java b/src/main/java/forestry/core/network/ForestryPacket.java index 0b1741b27..0d970dbf2 100755 --- a/src/main/java/forestry/core/network/ForestryPacket.java +++ b/src/main/java/forestry/core/network/ForestryPacket.java @@ -17,7 +17,7 @@ import cpw.mods.fml.common.network.internal.FMLProxyPacket; import io.netty.buffer.Unpooled; -public class ForestryPacket implements IForestryPacket { +public abstract class ForestryPacket implements IForestryPacket { protected static final String channel = "FOR"; diff --git a/src/main/java/forestry/core/network/GuiId.java b/src/main/java/forestry/core/network/GuiId.java index ee5b3c23a..24b886a21 100755 --- a/src/main/java/forestry/core/network/GuiId.java +++ b/src/main/java/forestry/core/network/GuiId.java @@ -36,6 +36,8 @@ public enum GuiId { BeealyzerGUI, BeehouseGUI, + + MinecartBeehouseGUI, BottlerGUI, diff --git a/src/main/java/forestry/core/network/ILocatedPacket.java b/src/main/java/forestry/core/network/ILocatedPacket.java index 73c8536ba..47400a405 100755 --- a/src/main/java/forestry/core/network/ILocatedPacket.java +++ b/src/main/java/forestry/core/network/ILocatedPacket.java @@ -10,12 +10,7 @@ ******************************************************************************/ package forestry.core.network; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - public interface ILocatedPacket { - TileEntity getTarget(World world); - int getPosX(); int getPosY(); diff --git a/src/main/java/forestry/core/network/IStreamableGui.java b/src/main/java/forestry/core/network/IStreamableGui.java index 89ebfdd39..471bd6da7 100644 --- a/src/main/java/forestry/core/network/IStreamableGui.java +++ b/src/main/java/forestry/core/network/IStreamableGui.java @@ -12,12 +12,7 @@ package forestry.core.network; import java.io.IOException; -import net.minecraft.util.ChunkCoordinates; - public interface IStreamableGui { - ChunkCoordinates getCoordinates(); - void writeGuiData(DataOutputStreamForestry data) throws IOException; - void readGuiData(DataInputStreamForestry data) throws IOException; } diff --git a/src/main/java/forestry/core/network/PacketAccessSwitch.java b/src/main/java/forestry/core/network/PacketAccessSwitch.java index 60b04edaa..878224a86 100644 --- a/src/main/java/forestry/core/network/PacketAccessSwitch.java +++ b/src/main/java/forestry/core/network/PacketAccessSwitch.java @@ -14,38 +14,26 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChunkCoordinates; -import forestry.apiculture.multiblock.IAlvearyController; -import forestry.apiculture.multiblock.TileAlveary; -import forestry.core.tiles.IRestrictedAccessTile; -import forestry.farming.multiblock.IFarmController; -import forestry.farming.tiles.TileFarm; +import forestry.core.access.IRestrictedAccess; +import forestry.core.tiles.ILocatable; public class PacketAccessSwitch extends PacketCoordinates implements IForestryPacketServer { public PacketAccessSwitch() { } - public PacketAccessSwitch(ChunkCoordinates coordinates) { - super(PacketIdServer.ACCESS_SWITCH, coordinates); + public PacketAccessSwitch(ILocatable tile) { + super(PacketIdServer.ACCESS_SWITCH, tile.getCoordinates()); } @Override public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException { TileEntity tile = getTarget(player.worldObj); - if (tile instanceof TileAlveary) { - TileAlveary tileAlveary = (TileAlveary) tile; - IAlvearyController alvearyController = tileAlveary.getAlvearyController(); - alvearyController.getAccessHandler().switchAccessRule(player); - } else if (tile instanceof TileFarm) { - TileFarm tileFarm = (TileFarm) tile; - IFarmController farmController = tileFarm.getFarmController(); - farmController.getAccessHandler().switchAccessRule(player); - } else if (tile instanceof IRestrictedAccessTile) { - IRestrictedAccessTile restrictedAccessTile = (IRestrictedAccessTile) tile; - restrictedAccessTile.getAccessHandler().switchAccessRule(player); + if (tile instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile; + restrictedAccessTile.getAccessHandler().switchAccess(player); } } } diff --git a/src/main/java/forestry/core/network/PacketAccessSwitchEntity.java b/src/main/java/forestry/core/network/PacketAccessSwitchEntity.java new file mode 100644 index 000000000..a3c2fb0a2 --- /dev/null +++ b/src/main/java/forestry/core/network/PacketAccessSwitchEntity.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; + +import forestry.core.access.IRestrictedAccess; + +public class PacketAccessSwitchEntity extends PacketEntityUpdate implements IForestryPacketServer { + + public PacketAccessSwitchEntity() { + } + + public PacketAccessSwitchEntity(Entity entity) { + super(PacketIdServer.ACCESS_SWITCH_ENTITY, entity); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException { + Entity target = getTarget(player.worldObj); + if (target instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) target; + restrictedAccessTile.getAccessHandler().switchAccess(player); + } + } +} diff --git a/src/main/java/forestry/core/network/PacketAccessUpdate.java b/src/main/java/forestry/core/network/PacketAccessUpdate.java new file mode 100644 index 000000000..37730f3a8 --- /dev/null +++ b/src/main/java/forestry/core/network/PacketAccessUpdate.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; + +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; + +public class PacketAccessUpdate extends PacketCoordinates implements IForestryPacketClient { + private IAccessHandler accessHandler; + + public PacketAccessUpdate() { + } + + public PacketAccessUpdate(IRestrictedAccess restrictedAccess, TileEntity tile) { + super(PacketIdClient.ACCESS_UPDATE, tile); + accessHandler = restrictedAccess.getAccessHandler(); + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + accessHandler.writeData(data); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { + TileEntity tile = getTarget(player.worldObj); + + if (tile instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile; + restrictedAccessTile.getAccessHandler().readData(data); + } + } +} diff --git a/src/main/java/forestry/core/network/PacketAccessUpdateEntity.java b/src/main/java/forestry/core/network/PacketAccessUpdateEntity.java new file mode 100644 index 000000000..f3ec15856 --- /dev/null +++ b/src/main/java/forestry/core/network/PacketAccessUpdateEntity.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; + +public class PacketAccessUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient { + private IAccessHandler accessHandler; + + public PacketAccessUpdateEntity() { + } + + public PacketAccessUpdateEntity(IRestrictedAccess restrictedAccess, Entity entity) { + super(PacketIdClient.ACCESS_UPDATE_ENTITY, entity); + accessHandler = restrictedAccess.getAccessHandler(); + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + accessHandler.writeData(data); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { + Entity tile = getTarget(player.worldObj); + + if (tile instanceof IRestrictedAccess) { + IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile; + restrictedAccessTile.getAccessHandler().readData(data); + } + } +} diff --git a/src/main/java/forestry/core/network/PacketCoordinates.java b/src/main/java/forestry/core/network/PacketCoordinates.java index a3d27da96..3fbe30a99 100755 --- a/src/main/java/forestry/core/network/PacketCoordinates.java +++ b/src/main/java/forestry/core/network/PacketCoordinates.java @@ -58,19 +58,21 @@ public abstract class PacketCoordinates extends ForestryPacket implements ILocat return new ChunkCoordinates(posX, posY, posZ); } + @Override public final int getPosX() { return posX; } + @Override public final int getPosY() { return posY; } + @Override public final int getPosZ() { return posZ; } - @Override public final TileEntity getTarget(World world) { return world.getTileEntity(posX, posY, posZ); } diff --git a/src/main/java/forestry/core/network/PacketEntityUpdate.java b/src/main/java/forestry/core/network/PacketEntityUpdate.java new file mode 100644 index 000000000..85acb8f51 --- /dev/null +++ b/src/main/java/forestry/core/network/PacketEntityUpdate.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.world.World; + +public abstract class PacketEntityUpdate extends ForestryPacket implements ILocatedPacket { + // sending + private Entity entity; + // receiving + private int entityId; + + public PacketEntityUpdate() { + } + + public PacketEntityUpdate(IPacketId id, Entity entity) { + super(id); + this.entity = entity; + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + data.writeVarInt(entity.getEntityId()); + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + super.readData(data); + entityId = data.readVarInt(); + } + + public Entity getTarget(World world) { + return world.getEntityByID(entityId); + } + + @Override + public int getPosX() { + return (int) entity.posX; + } + + @Override + public int getPosY() { + return (int) entity.posY; + } + + @Override + public int getPosZ() { + return (int) entity.posZ; + } +} diff --git a/src/main/java/forestry/core/network/PacketErrorUpdateEntity.java b/src/main/java/forestry/core/network/PacketErrorUpdateEntity.java new file mode 100644 index 000000000..9ff701df6 --- /dev/null +++ b/src/main/java/forestry/core/network/PacketErrorUpdateEntity.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; + +import forestry.api.core.IErrorLogic; +import forestry.api.core.IErrorLogicSource; +import forestry.core.proxy.Proxies; + +public class PacketErrorUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient { + private IErrorLogic errorLogic; + + public PacketErrorUpdateEntity() { + } + + public PacketErrorUpdateEntity(Entity entity, IErrorLogicSource errorLogicSource) { + super(PacketIdClient.ERROR_UPDATE_ENTITY, entity); + this.errorLogic = errorLogicSource.getErrorLogic(); + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + errorLogic.writeData(data); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { + Entity entity = getTarget(Proxies.common.getRenderWorld()); + if (entity instanceof IErrorLogicSource) { + IErrorLogicSource errorSourceTile = (IErrorLogicSource) entity; + errorLogic = errorSourceTile.getErrorLogic(); + errorLogic.readData(data); + } + } +} diff --git a/src/main/java/forestry/core/network/PacketGuiUpdate.java b/src/main/java/forestry/core/network/PacketGuiUpdate.java index 574343a7c..8c8440613 100644 --- a/src/main/java/forestry/core/network/PacketGuiUpdate.java +++ b/src/main/java/forestry/core/network/PacketGuiUpdate.java @@ -16,6 +16,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import forestry.core.proxy.Proxies; +import forestry.core.tiles.ILocatable; public class PacketGuiUpdate extends PacketCoordinates implements IForestryPacketClient { @@ -24,7 +25,7 @@ public class PacketGuiUpdate extends PacketCoordinates implements IForestryPacke public PacketGuiUpdate() { } - public PacketGuiUpdate(IStreamableGui guiDataTile) { + public PacketGuiUpdate(T guiDataTile) { super(PacketIdClient.GUI_UPDATE, guiDataTile.getCoordinates()); this.guiDataTile = guiDataTile; } diff --git a/src/main/java/forestry/core/network/PacketGuiUpdateEntity.java b/src/main/java/forestry/core/network/PacketGuiUpdateEntity.java new file mode 100644 index 000000000..33d618cbc --- /dev/null +++ b/src/main/java/forestry/core/network/PacketGuiUpdateEntity.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.proxy.Proxies; + +public class PacketGuiUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient { + private IStreamableGui streamableGui; + + public PacketGuiUpdateEntity() { + } + + public PacketGuiUpdateEntity(IStreamableGui streamableGui, Entity entity) { + super(PacketIdClient.GUI_UPDATE_ENTITY, entity); + this.streamableGui = streamableGui; + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + streamableGui.writeGuiData(data); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { + Entity entity = getTarget(Proxies.common.getRenderWorld()); + if (entity instanceof IStreamableGui) { + ((IStreamableGui) entity).readGuiData(data); + } + } +} diff --git a/src/main/java/forestry/core/network/PacketIdClient.java b/src/main/java/forestry/core/network/PacketIdClient.java index fccb52993..99eccf599 100644 --- a/src/main/java/forestry/core/network/PacketIdClient.java +++ b/src/main/java/forestry/core/network/PacketIdClient.java @@ -17,10 +17,14 @@ public enum PacketIdClient implements IPacketId { // Core Gui ERROR_UPDATE(new PacketErrorUpdate()), + ERROR_UPDATE_ENTITY(new PacketErrorUpdateEntity()), GUI_UPDATE(new PacketGuiUpdate()), + GUI_UPDATE_ENTITY(new PacketGuiUpdateEntity()), GUI_LAYOUT_SELECT(new PacketGuiLayoutSelect()), GUI_ENERGY(new PacketGuiEnergy()), SOCKET_UPDATE(new PacketSocketUpdate()), + ACCESS_UPDATE(new PacketAccessUpdate()), + ACCESS_UPDATE_ENTITY(new PacketAccessUpdateEntity()), // Core Tile Entities TILE_FORESTRY_UPDATE(new PacketTileStream()), @@ -37,6 +41,7 @@ public enum PacketIdClient implements IPacketId { // Apiculture TILE_FORESTRY_ACTIVE, BEE_LOGIC_ACTIVE, + BEE_LOGIC_ACTIVE_ENTITY, HABITAT_BIOME_POINTER, CANDLE_UPDATE, IMPRINT_SELECTION_RESPONSE, diff --git a/src/main/java/forestry/core/network/PacketIdServer.java b/src/main/java/forestry/core/network/PacketIdServer.java index a053fde0a..b7cfc0b8d 100644 --- a/src/main/java/forestry/core/network/PacketIdServer.java +++ b/src/main/java/forestry/core/network/PacketIdServer.java @@ -19,9 +19,13 @@ public enum PacketIdServer implements IPacketId { GUI_SELECTION_REQUEST(new PacketGuiSelectRequest()), PIPETTE_CLICK(new PacketPipetteClick()), ACCESS_SWITCH(new PacketAccessSwitch()), + ACCESS_SWITCH_ENTITY(new PacketAccessSwitchEntity()), CHIPSET_CLICK(new PacketChipsetClick()), SOLDERING_IRON_CLICK(new PacketSolderingIronClick()), + // Apiculture + BEE_LOGIC_ACTIVE_ENTITY_REQUEST, + // Factory WORKTABLE_NEI_SELECT, diff --git a/src/main/java/forestry/core/proxy/ProxyRender.java b/src/main/java/forestry/core/proxy/ProxyRender.java index 44d1f923b..0dc6de5dd 100755 --- a/src/main/java/forestry/core/proxy/ProxyRender.java +++ b/src/main/java/forestry/core/proxy/ProxyRender.java @@ -75,7 +75,7 @@ public class ProxyRender { /* FX */ - public void addBeeHiveFX(String texture, World world, ChunkCoordinates coordinates, int color) { + public void addBeeHiveFX(String texture, World world, double d1, double d2, double d3, int color) { } public void addEntitySwarmFX(World world, double d1, double d2, double d3) { diff --git a/src/main/java/forestry/core/proxy/ProxyRenderClient.java b/src/main/java/forestry/core/proxy/ProxyRenderClient.java index ecb4d48ed..17f49b142 100644 --- a/src/main/java/forestry/core/proxy/ProxyRenderClient.java +++ b/src/main/java/forestry/core/proxy/ProxyRenderClient.java @@ -141,12 +141,12 @@ public class ProxyRenderClient extends ProxyRender { } @Override - public void addBeeHiveFX(String icon, World world, ChunkCoordinates coordinates, int color) { + public void addBeeHiveFX(String icon, World world, double d1, double d2, double d3, int color) { if (!shouldSpawnParticle(world)) { return; } - EntityFX fx = new EntityFXBee(world, coordinates.posX + 0.5D, coordinates.posY + 0.5D, coordinates.posZ + 0.5D, color); + EntityFX fx = new EntityFXBee(world, d1, d2, d3, color); fx.setParticleIcon(TextureManager.getInstance().getDefault(icon)); ParticleRenderer.getInstance().addEffect(fx); } diff --git a/src/main/java/forestry/core/tiles/TileBase.java b/src/main/java/forestry/core/tiles/TileBase.java index 0e3ae518f..b1374a1f4 100644 --- a/src/main/java/forestry/core/tiles/TileBase.java +++ b/src/main/java/forestry/core/tiles/TileBase.java @@ -29,11 +29,6 @@ public abstract class TileBase extends TileForestry implements IHintSource { this.hints = hints; } - @Override - public boolean hasHints() { - return hints != null && hints.length > 0; - } - @Override public String[] getHints() { return hints; diff --git a/src/main/java/forestry/core/tiles/TileEscritoire.java b/src/main/java/forestry/core/tiles/TileEscritoire.java index 0e815b295..4d6b5ad74 100644 --- a/src/main/java/forestry/core/tiles/TileEscritoire.java +++ b/src/main/java/forestry/core/tiles/TileEscritoire.java @@ -203,6 +203,9 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender @Override public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { super.setInventorySlotContents(slotIndex, itemstack); + if (tile.worldObj == null) { + return; + } if (slotIndex == SLOT_ANALYZE && !tile.worldObj.isRemote) { if (!AlleleManager.alleleRegistry.isIndividual(getStackInSlot(SLOT_ANALYZE)) && getStackInSlot(SLOT_ANALYZE) != null) { ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_ANALYZE)); diff --git a/src/main/java/forestry/core/tiles/TileForestry.java b/src/main/java/forestry/core/tiles/TileForestry.java index 740e12655..f2f233f28 100644 --- a/src/main/java/forestry/core/tiles/TileForestry.java +++ b/src/main/java/forestry/core/tiles/TileForestry.java @@ -34,6 +34,7 @@ import forestry.api.core.IErrorLogicSource; import forestry.core.access.AccessHandler; import forestry.core.access.EnumAccess; import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; import forestry.core.errors.ErrorLogic; import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; @@ -49,7 +50,7 @@ import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") -public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate, IRestrictedAccessTile, ITitled { +public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate, IRestrictedAccess, ITitled, ILocatable { private static final Random rand = new Random(); @@ -179,18 +180,6 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE orientation = ForgeDirection.getOrientation(data.readByte()); } - @Override - public void writeGuiData(DataOutputStreamForestry data) throws IOException { - accessHandler.writeData(data); - errorHandler.writeData(data); - } - - @Override - public void readGuiData(DataInputStreamForestry data) throws IOException { - accessHandler.readData(data); - errorHandler.readData(data); - } - public void onRemoval() { } @@ -264,7 +253,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE */ @Override public String getUnlocalizedTitle() { - String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.", ""); + String blockUnlocalizedName = getBlockType().getUnlocalizedName(); return blockUnlocalizedName + '.' + getBlockMetadata() + ".name"; } @@ -366,7 +355,6 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE return getInternalInventory().canExtractItem(slotIndex, itemStack, side); } - @Override public final ChunkCoordinates getCoordinates() { return new ChunkCoordinates(xCoord, yCoord, zCoord); } diff --git a/src/main/java/forestry/core/tiles/TilePowered.java b/src/main/java/forestry/core/tiles/TilePowered.java index b5ea3dda0..cc223aee4 100644 --- a/src/main/java/forestry/core/tiles/TilePowered.java +++ b/src/main/java/forestry/core/tiles/TilePowered.java @@ -23,13 +23,14 @@ import forestry.core.circuits.ISpeedUpgradable; import forestry.core.errors.EnumErrorCode; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IStreamableGui; import forestry.core.render.TankRenderInfo; import forestry.energy.EnergyManager; import buildcraft.api.tiles.IHasWork; @Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles") -public abstract class TilePowered extends TileBase implements IRenderableTile, IPowerHandler, IHasWork, ISpeedUpgradable { +public abstract class TilePowered extends TileBase implements IRenderableTile, IPowerHandler, IHasWork, ISpeedUpgradable, IStreamableGui { private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks @@ -157,7 +158,6 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I @Override public void writeGuiData(DataOutputStreamForestry data) throws IOException { - super.writeGuiData(data); energyManager.writeData(data); data.writeVarInt(workCounter); data.writeVarInt(getTicksPerWorkCycle()); @@ -165,7 +165,6 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I @Override public void readGuiData(DataInputStreamForestry data) throws IOException { - super.readGuiData(data); energyManager.readData(data); workCounter = data.readVarInt(); ticksPerWorkCycle = data.readVarInt(); diff --git a/src/main/java/forestry/core/tiles/TileUtil.java b/src/main/java/forestry/core/tiles/TileUtil.java index 21a727108..48e180a8f 100644 --- a/src/main/java/forestry/core/tiles/TileUtil.java +++ b/src/main/java/forestry/core/tiles/TileUtil.java @@ -52,7 +52,7 @@ public abstract class TileUtil { } public static IInventory getInventoryFromTile(TileEntity tile, ForgeDirection side) { - if (tile == null || !(tile instanceof IInventory)) { + if (!(tile instanceof IInventory)) { return null; } diff --git a/src/main/java/forestry/core/utils/InventoryUtil.java b/src/main/java/forestry/core/utils/InventoryUtil.java index 381376e59..d645626ae 100644 --- a/src/main/java/forestry/core/utils/InventoryUtil.java +++ b/src/main/java/forestry/core/utils/InventoryUtil.java @@ -20,6 +20,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -672,4 +674,32 @@ public abstract class InventoryUtil { world.spawnEntityInWorld(entityitem); } } + + /* NBT */ + public static void readFromNBT(IInventory inventory, NBTTagCompound nbttagcompound) { + if (!nbttagcompound.hasKey(inventory.getInventoryName())) { + return; + } + + NBTTagList nbttaglist = nbttagcompound.getTagList(inventory.getInventoryName(), 10); + + for (int j = 0; j < nbttaglist.tagCount(); ++j) { + NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); + int index = nbttagcompound2.getByte("Slot"); + inventory.setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(nbttagcompound2)); + } + } + + public static void writeToNBT(IInventory inventory, NBTTagCompound nbttagcompound) { + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (inventory.getStackInSlot(i) != null) { + NBTTagCompound nbttagcompound2 = new NBTTagCompound(); + nbttagcompound2.setByte("Slot", (byte) i); + inventory.getStackInSlot(i).writeToNBT(nbttagcompound2); + nbttaglist.appendTag(nbttagcompound2); + } + } + nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist); + } } diff --git a/src/main/java/forestry/energy/GuiHandlerEnergy.java b/src/main/java/forestry/energy/GuiHandlerEnergy.java index fb01be914..ba6b5f79d 100755 --- a/src/main/java/forestry/energy/GuiHandlerEnergy.java +++ b/src/main/java/forestry/energy/GuiHandlerEnergy.java @@ -17,6 +17,7 @@ import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.core.network.PacketSocketUpdate; import forestry.core.proxy.Proxies; +import forestry.core.tiles.TileUtil; import forestry.energy.gui.ContainerEngineBiogas; import forestry.energy.gui.ContainerEngineElectric; import forestry.energy.gui.ContainerEnginePeat; @@ -42,16 +43,16 @@ public class GuiHandlerEnergy extends GuiHandlerBase { switch (GuiId.values()[id]) { case EngineBiogasGUI: - return new GuiEngineBiogas(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class)); + return new GuiEngineBiogas(player.inventory, TileUtil.getTile(world, x, y, z, TileEngineBiogas.class)); case EnginePeatGUI: - return new GuiEnginePeat(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class)); + return new GuiEnginePeat(player.inventory, TileUtil.getTile(world, x, y, z, TileEnginePeat.class)); case EngineElectricGUI: - return new GuiEngineElectric(player.inventory, getTile(world, x, y, z, player, TileEngineElectric.class)); + return new GuiEngineElectric(player.inventory, TileUtil.getTile(world, x, y, z, TileEngineElectric.class)); case GeneratorGUI: - return new GuiGenerator(player.inventory, getTile(world, x, y, z, player, TileGenerator.class)); + return new GuiGenerator(player.inventory, TileUtil.getTile(world, x, y, z, TileGenerator.class)); default: return null; @@ -68,18 +69,18 @@ public class GuiHandlerEnergy extends GuiHandlerBase { switch (GuiId.values()[id]) { case EngineBiogasGUI: - return new ContainerEngineBiogas(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class)); + return new ContainerEngineBiogas(player.inventory, TileUtil.getTile(world, x, y, z, TileEngineBiogas.class)); case EnginePeatGUI: - return new ContainerEnginePeat(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class)); + return new ContainerEnginePeat(player.inventory, TileUtil.getTile(world, x, y, z, TileEnginePeat.class)); case EngineElectricGUI: - TileEngineElectric tile = getTile(world, x, y, z, player, TileEngineElectric.class); + TileEngineElectric tile = TileUtil.getTile(world, x, y, z, TileEngineElectric.class); Proxies.net.sendToPlayer(new PacketSocketUpdate(tile), player); return new ContainerEngineElectric(player.inventory, tile); case GeneratorGUI: - return new ContainerGenerator(player.inventory, getTile(world, x, y, z, player, TileGenerator.class)); + return new ContainerGenerator(player.inventory, TileUtil.getTile(world, x, y, z, TileGenerator.class)); default: return null; diff --git a/src/main/java/forestry/factory/GuiHandlerFactory.java b/src/main/java/forestry/factory/GuiHandlerFactory.java index 6671b272b..32b0fe4a2 100755 --- a/src/main/java/forestry/factory/GuiHandlerFactory.java +++ b/src/main/java/forestry/factory/GuiHandlerFactory.java @@ -15,6 +15,7 @@ import net.minecraft.world.World; import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; +import forestry.core.tiles.TileUtil; import forestry.factory.gui.ContainerBottler; import forestry.factory.gui.ContainerCarpenter; import forestry.factory.gui.ContainerCentrifuge; @@ -58,34 +59,34 @@ public class GuiHandlerFactory extends GuiHandlerBase { switch (GuiId.values()[id]) { case BottlerGUI: - return new GuiBottler(player.inventory, getTile(world, x, y, z, player, TileBottler.class)); + return new GuiBottler(player.inventory, TileUtil.getTile(world, x, y, z, TileBottler.class)); case CarpenterGUI: - return new GuiCarpenter(player.inventory, getTile(world, x, y, z, player, TileCarpenter.class)); + return new GuiCarpenter(player.inventory, TileUtil.getTile(world, x, y, z, TileCarpenter.class)); case CentrifugeGUI: - return new GuiCentrifuge(player.inventory, getTile(world, x, y, z, player, TileCentrifuge.class)); + return new GuiCentrifuge(player.inventory, TileUtil.getTile(world, x, y, z, TileCentrifuge.class)); case FabricatorGUI: - return new GuiFabricator(player.inventory, getTile(world, x, y, z, player, TileFabricator.class)); + return new GuiFabricator(player.inventory, TileUtil.getTile(world, x, y, z, TileFabricator.class)); case FermenterGUI: - return new GuiFermenter(player.inventory, getTile(world, x, y, z, player, TileFermenter.class)); + return new GuiFermenter(player.inventory, TileUtil.getTile(world, x, y, z, TileFermenter.class)); case MoistenerGUI: - return new GuiMoistener(player.inventory, getTile(world, x, y, z, player, TileMoistener.class)); + return new GuiMoistener(player.inventory, TileUtil.getTile(world, x, y, z, TileMoistener.class)); case RaintankGUI: - return new GuiRaintank(player.inventory, getTile(world, x, y, z, player, TileRaintank.class)); + return new GuiRaintank(player.inventory, TileUtil.getTile(world, x, y, z, TileRaintank.class)); case SqueezerGUI: - return new GuiSqueezer(player.inventory, getTile(world, x, y, z, player, TileSqueezer.class)); + return new GuiSqueezer(player.inventory, TileUtil.getTile(world, x, y, z, TileSqueezer.class)); case StillGUI: - return new GuiStill(player.inventory, getTile(world, x, y, z, player, TileStill.class)); + return new GuiStill(player.inventory, TileUtil.getTile(world, x, y, z, TileStill.class)); case WorktableGUI: - return new GuiWorktable(player, getTile(world, x, y, z, player, TileWorktable.class)); + return new GuiWorktable(player, TileUtil.getTile(world, x, y, z, TileWorktable.class)); default: return null; @@ -103,34 +104,34 @@ public class GuiHandlerFactory extends GuiHandlerBase { switch (GuiId.values()[id]) { case BottlerGUI: - return new ContainerBottler(player.inventory, getTile(world, x, y, z, player, TileBottler.class)); + return new ContainerBottler(player.inventory, TileUtil.getTile(world, x, y, z, TileBottler.class)); case CarpenterGUI: - return new ContainerCarpenter(player.inventory, getTile(world, x, y, z, player, TileCarpenter.class)); + return new ContainerCarpenter(player.inventory, TileUtil.getTile(world, x, y, z, TileCarpenter.class)); case CentrifugeGUI: - return new ContainerCentrifuge(player.inventory, getTile(world, x, y, z, player, TileCentrifuge.class)); + return new ContainerCentrifuge(player.inventory, TileUtil.getTile(world, x, y, z, TileCentrifuge.class)); case FabricatorGUI: - return new ContainerFabricator(player.inventory, getTile(world, x, y, z, player, TileFabricator.class)); + return new ContainerFabricator(player.inventory, TileUtil.getTile(world, x, y, z, TileFabricator.class)); case FermenterGUI: - return new ContainerFermenter(player.inventory, getTile(world, x, y, z, player, TileFermenter.class)); + return new ContainerFermenter(player.inventory, TileUtil.getTile(world, x, y, z, TileFermenter.class)); case MoistenerGUI: - return new ContainerMoistener(player.inventory, getTile(world, x, y, z, player, TileMoistener.class)); + return new ContainerMoistener(player.inventory, TileUtil.getTile(world, x, y, z, TileMoistener.class)); case RaintankGUI: - return new ContainerRaintank(player.inventory, getTile(world, x, y, z, player, TileRaintank.class)); + return new ContainerRaintank(player.inventory, TileUtil.getTile(world, x, y, z, TileRaintank.class)); case SqueezerGUI: - return new ContainerSqueezer(player.inventory, getTile(world, x, y, z, player, TileSqueezer.class)); + return new ContainerSqueezer(player.inventory, TileUtil.getTile(world, x, y, z, TileSqueezer.class)); case StillGUI: - return new ContainerStill(player.inventory, getTile(world, x, y, z, player, TileStill.class)); + return new ContainerStill(player.inventory, TileUtil.getTile(world, x, y, z, TileStill.class)); case WorktableGUI: - return new ContainerWorktable(player, getTile(world, x, y, z, player, TileWorktable.class)); + return new ContainerWorktable(player, TileUtil.getTile(world, x, y, z, TileWorktable.class)); default: return null; diff --git a/src/main/java/forestry/farming/GuiHandlerFarming.java b/src/main/java/forestry/farming/GuiHandlerFarming.java index a40e93dea..eae4f69ef 100755 --- a/src/main/java/forestry/farming/GuiHandlerFarming.java +++ b/src/main/java/forestry/farming/GuiHandlerFarming.java @@ -17,6 +17,7 @@ import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.core.network.PacketSocketUpdate; import forestry.core.proxy.Proxies; +import forestry.core.tiles.TileUtil; import forestry.farming.gui.ContainerFarm; import forestry.farming.gui.GuiFarm; import forestry.farming.tiles.TileFarm; @@ -32,7 +33,7 @@ public class GuiHandlerFarming extends GuiHandlerBase { switch (GuiId.values()[id]) { case MultiFarmGUI: - TileFarm tile = getTile(world, x, y, z, player, TileFarm.class); + TileFarm tile = TileUtil.getTile(world, x, y, z, TileFarm.class); Proxies.net.sendToPlayer(new PacketSocketUpdate(tile), player); return new ContainerFarm(player.inventory, tile); default: @@ -49,7 +50,7 @@ public class GuiHandlerFarming extends GuiHandlerBase { switch (GuiId.values()[id]) { case MultiFarmGUI: - return new GuiFarm(player, getTile(world, x, y, z, player, TileFarm.class)); + return new GuiFarm(player, TileUtil.getTile(world, x, y, z, TileFarm.class)); default: return null; diff --git a/src/main/java/forestry/farming/multiblock/FakeFarmController.java b/src/main/java/forestry/farming/multiblock/FakeFarmController.java index f9bee3181..7ca73476e 100644 --- a/src/main/java/forestry/farming/multiblock/FakeFarmController.java +++ b/src/main/java/forestry/farming/multiblock/FakeFarmController.java @@ -14,7 +14,6 @@ import java.io.IOException; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; @@ -179,11 +178,6 @@ public class FakeFarmController implements IFarmController { return FakeTankManager.instance; } - @Override - public ChunkCoordinates getCoordinates() { - return null; - } - @Override public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index 2c797a1ea..3626e2fce 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -67,8 +67,6 @@ import forestry.core.multiblock.MultiblockValidationException; import forestry.core.multiblock.rectangular.RectangularMultiblockControllerBase; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; -import forestry.core.network.PacketGuiUpdate; -import forestry.core.proxy.Proxies; import forestry.core.tiles.ILiquidTankTile; import forestry.core.utils.Log; import forestry.core.utils.PlayerUtil; @@ -364,9 +362,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen @Override public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { - PacketGuiUpdate packet = new PacketGuiUpdate(this); - Proxies.net.sendNetworkPacket(packet, worldObj); - if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) { // pipes connected to this need to update for (IMultiblockPart part : connectedParts) { @@ -381,7 +376,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen @Override public void writeGuiData(DataOutputStreamForestry data) throws IOException { - super.writeGuiData(data); tankManager.writeData(data); hydrationManager.writeData(data); fertilizerManager.writeData(data); @@ -389,7 +383,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen @Override public void readGuiData(DataInputStreamForestry data) throws IOException { - super.readGuiData(data); tankManager.readData(data); hydrationManager.readData(data); fertilizerManager.readData(data); diff --git a/src/main/java/forestry/farming/multiblock/IFarmController.java b/src/main/java/forestry/farming/multiblock/IFarmController.java index 2a42677fa..5b584d538 100644 --- a/src/main/java/forestry/farming/multiblock/IFarmController.java +++ b/src/main/java/forestry/farming/multiblock/IFarmController.java @@ -12,14 +12,15 @@ package forestry.farming.multiblock; import forestry.api.core.IErrorLogicSource; import forestry.api.farming.IFarmHousing; +import forestry.core.access.IRestrictedAccess; import forestry.core.circuits.ISocketable; import forestry.core.fluids.ITankManager; import forestry.core.inventory.IInventoryAdapter; +import forestry.core.network.IStreamableGui; import forestry.core.tiles.IClimatised; -import forestry.core.tiles.IRestrictedAccessTile; import forestry.farming.gui.IFarmLedgerDelegate; -public interface IFarmController extends IFarmHousing, ISocketable, IClimatised, IRestrictedAccessTile, IErrorLogicSource { +public interface IFarmController extends IFarmHousing, ISocketable, IClimatised, IRestrictedAccess, IErrorLogicSource, IStreamableGui { IFarmLedgerDelegate getFarmLedgerDelegate(); IInventoryAdapter getInternalInventory(); diff --git a/src/main/java/forestry/farming/tiles/TileFarm.java b/src/main/java/forestry/farming/tiles/TileFarm.java index db18c2075..4d2753909 100644 --- a/src/main/java/forestry/farming/tiles/TileFarm.java +++ b/src/main/java/forestry/farming/tiles/TileFarm.java @@ -15,7 +15,6 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.StatCollector; import forestry.api.circuits.ICircuitSocketType; @@ -23,6 +22,9 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.core.IErrorLogicSource; import forestry.api.farming.IFarmComponent; +import forestry.core.access.EnumAccess; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; import forestry.core.circuits.ISocketable; import forestry.core.config.Config; import forestry.core.gui.IHintSource; @@ -39,7 +41,7 @@ import forestry.farming.multiblock.FarmController; import forestry.farming.multiblock.IFarmController; import forestry.farming.render.EnumFarmBlockTexture; -public abstract class TileFarm extends RectangularMultiblockTileEntityBase implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource { +public abstract class TileFarm extends RectangularMultiblockTileEntityBase implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IRestrictedAccess { public static final int TYPE_PLAIN = 0; public static final int TYPE_REVERSE = 1; @@ -169,11 +171,6 @@ public abstract class TileFarm extends RectangularMultiblockTileEntityBase imple } /* IHintSource */ - @Override - public boolean hasHints() { - return Config.hints.get("farm").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("farm"); @@ -201,11 +198,6 @@ public abstract class TileFarm extends RectangularMultiblockTileEntityBase imple } /* IStreamableGui */ - @Override - public ChunkCoordinates getCoordinates() { - return getFarmController().getCoordinates(); - } - @Override public void writeGuiData(DataOutputStreamForestry data) throws IOException { getFarmController().writeGuiData(data); @@ -221,4 +213,14 @@ public abstract class TileFarm extends RectangularMultiblockTileEntityBase imple public IErrorLogic getErrorLogic() { return getFarmController().getErrorLogic(); } + + @Override + public IAccessHandler getAccessHandler() { + return getFarmController().getAccessHandler(); + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + getFarmController().onSwitchAccess(oldAccess, newAccess); + } } diff --git a/src/main/java/forestry/farming/tiles/TileValve.java b/src/main/java/forestry/farming/tiles/TileValve.java index 23508ded3..76c522f6a 100644 --- a/src/main/java/forestry/farming/tiles/TileValve.java +++ b/src/main/java/forestry/farming/tiles/TileValve.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.farming.tiles; -import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -58,9 +56,4 @@ public class TileValve extends TileFarm implements ILiquidTankTile, IFluidHandle public ITankManager getTankManager() { return getFarmController().getTankManager(); } - - @Override - public World getWorld() { - return worldObj; - } } diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java index 2c97d73a1..ca106546d 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java @@ -37,11 +37,6 @@ public class ItemFlutterlyzer extends ItemAlyzer { } /* IHINTSOURCE */ - @Override - public boolean hasHints() { - return Config.hints.get("flutterlyzer") != null && Config.hints.get("flutterlyzer").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("flutterlyzer"); diff --git a/src/main/java/forestry/mail/GuiHandlerMail.java b/src/main/java/forestry/mail/GuiHandlerMail.java index 35ab68282..5e3f6afd1 100755 --- a/src/main/java/forestry/mail/GuiHandlerMail.java +++ b/src/main/java/forestry/mail/GuiHandlerMail.java @@ -16,6 +16,7 @@ import net.minecraft.world.World; import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; +import forestry.core.tiles.TileUtil; import forestry.mail.gui.ContainerCatalogue; import forestry.mail.gui.ContainerLetter; import forestry.mail.gui.ContainerMailbox; @@ -70,13 +71,13 @@ public class GuiHandlerMail extends GuiHandlerBase { } case MailboxGUI: - return new GuiMailbox(player.inventory, getTile(world, x, y, z, player, TileMailbox.class)); + return new GuiMailbox(player.inventory, TileUtil.getTile(world, x, y, z, TileMailbox.class)); case PhilatelistGUI: - return new GuiPhilatelist(player.inventory, getTile(world, x, y, z, player, TilePhilatelist.class)); + return new GuiPhilatelist(player.inventory, TileUtil.getTile(world, x, y, z, TilePhilatelist.class)); case TraderGUI: - return new GuiTrader(player.inventory, getTile(world, x, y, z, player, TileTrader.class)); + return new GuiTrader(player.inventory, TileUtil.getTile(world, x, y, z, TileTrader.class)); case TraderNameGUI: - return new GuiTradeName(getTile(world, x, y, z, player, TileTrader.class)); + return new GuiTradeName(TileUtil.getTile(world, x, y, z, TileTrader.class)); default: return null; @@ -116,13 +117,13 @@ public class GuiHandlerMail extends GuiHandlerBase { } case MailboxGUI: - return new ContainerMailbox(player.inventory, getTile(world, x, y, z, player, TileMailbox.class)); + return new ContainerMailbox(player.inventory, TileUtil.getTile(world, x, y, z, TileMailbox.class)); case PhilatelistGUI: - return new ContainerPhilatelist(player.inventory, getTile(world, x, y, z, player, TilePhilatelist.class)); + return new ContainerPhilatelist(player.inventory, TileUtil.getTile(world, x, y, z, TilePhilatelist.class)); case TraderGUI: - return new ContainerTrader(player.inventory, getTile(world, x, y, z, player, TileTrader.class)); + return new ContainerTrader(player.inventory, TileUtil.getTile(world, x, y, z, TileTrader.class)); case TraderNameGUI: - return new ContainerTradeName(getTile(world, x, y, z, player, TileTrader.class)); + return new ContainerTradeName(TileUtil.getTile(world, x, y, z, TileTrader.class)); default: return null; diff --git a/src/main/java/forestry/mail/items/ItemLetter.java b/src/main/java/forestry/mail/items/ItemLetter.java index 09464bde4..d655f8625 100755 --- a/src/main/java/forestry/mail/items/ItemLetter.java +++ b/src/main/java/forestry/mail/items/ItemLetter.java @@ -292,11 +292,6 @@ public class ItemLetter extends ItemInventoried { } /* IHINTSOURCE */ - @Override - public boolean hasHints() { - return Config.hints.get("letter") != null && Config.hints.get("letter").length > 0; - } - @Override public String[] getHints() { return Config.hints.get("letter"); diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index e609891b1..e10c89ba2 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -74,6 +74,7 @@ import forestry.apiculture.blocks.BlockBeehives; import forestry.apiculture.blocks.BlockCandle; import forestry.apiculture.blocks.BlockStump; import forestry.apiculture.commands.CommandBee; +import forestry.apiculture.entities.EntityMinecartBeehouse; import forestry.apiculture.flowers.FlowerRegistry; import forestry.apiculture.genetics.BeeBranchDefinition; import forestry.apiculture.genetics.BeeDefinition; @@ -107,6 +108,7 @@ import forestry.apiculture.items.ItemHabitatLocator; import forestry.apiculture.items.ItemHiveFrame; import forestry.apiculture.items.ItemHoneycomb; import forestry.apiculture.items.ItemImprinter; +import forestry.apiculture.items.ItemMinecartBeehouse; import forestry.apiculture.items.ItemWaxCast; import forestry.apiculture.multiblock.TileAlveary; import forestry.apiculture.multiblock.TileAlvearyFan; @@ -117,7 +119,9 @@ import forestry.apiculture.multiblock.TileAlvearySieve; import forestry.apiculture.multiblock.TileAlvearyStabiliser; import forestry.apiculture.multiblock.TileAlvearySwarmer; import forestry.apiculture.network.PacketActiveUpdate; -import forestry.apiculture.network.PacketBeekeepingLogicActive; +import forestry.apiculture.network.PacketBeeLogicActive; +import forestry.apiculture.network.PacketBeeLogicActiveEntity; +import forestry.apiculture.network.PacketBeeLogicEntityRequest; import forestry.apiculture.network.PacketCandleUpdate; import forestry.apiculture.network.PacketHabitatBiomePointer; import forestry.apiculture.network.PacketImprintSelectionResponse; @@ -148,11 +152,13 @@ import forestry.core.items.ItemOverlay; import forestry.core.items.ItemOverlay.OverlayInfo; import forestry.core.items.ItemScoop; import forestry.core.network.PacketIdClient; +import forestry.core.network.PacketIdServer; import forestry.core.proxy.Proxies; import forestry.core.recipes.RecipeUtil; import forestry.core.recipes.ShapedRecipeCustom; import forestry.core.tiles.MachineDefinition; import forestry.core.tiles.TileAnalyzer; +import forestry.core.utils.EntityUtil; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; import forestry.core.utils.Stack; @@ -378,6 +384,7 @@ public class PluginApiculture extends ForestryPlugin { GameRegistry.registerTileEntity(TileAlvearySieve.class, "forestry.AlvearySieve"); GameRegistry.registerTileEntity(TileCandle.class, "forestry.Candle"); + EntityUtil.registerEntity(EntityMinecartBeehouse.class, "cart.beehouse", 1, 0x000000, 0xffffff, 256, 3, true); BeeManager.villageBees[0].add(BeeDefinition.FOREST.getGenome()); BeeManager.villageBees[0].add(BeeDefinition.MEADOWS.getGenome()); @@ -501,9 +508,12 @@ public class PluginApiculture extends ForestryPlugin { public void registerPacketHandlers() { PacketIdClient.IMPRINT_SELECTION_RESPONSE.setPacketHandler(new PacketImprintSelectionResponse()); PacketIdClient.TILE_FORESTRY_ACTIVE.setPacketHandler(new PacketActiveUpdate()); - PacketIdClient.BEE_LOGIC_ACTIVE.setPacketHandler(new PacketBeekeepingLogicActive()); + PacketIdClient.BEE_LOGIC_ACTIVE.setPacketHandler(new PacketBeeLogicActive()); + PacketIdClient.BEE_LOGIC_ACTIVE_ENTITY.setPacketHandler(new PacketBeeLogicActiveEntity()); PacketIdClient.HABITAT_BIOME_POINTER.setPacketHandler(new PacketHabitatBiomePointer()); PacketIdClient.CANDLE_UPDATE.setPacketHandler(new PacketCandleUpdate()); + + PacketIdServer.BEE_LOGIC_ACTIVE_ENTITY_REQUEST.setPacketHandler(new PacketBeeLogicEntityRequest()); } @Override @@ -519,6 +529,8 @@ public class PluginApiculture extends ForestryPlugin { ForestryItem.habitatLocator.registerItem(new ItemHabitatLocator(), "habitatLocator"); ForestryItem.imprinter.registerItem((new ItemImprinter()), "imprinter"); + ForestryItem.minecartBeehouse.registerItem(new ItemMinecartBeehouse(), "cart.beehouse"); + // / COMB FRAMES ForestryItem.frameUntreated.registerItem(new ItemHiveFrame(80, 0.9f), "frameUntreated"); ForestryItem.frameImpregnated.registerItem(new ItemHiveFrame(240, 0.4f), "frameImpregnated"); @@ -639,6 +651,11 @@ public class PluginApiculture extends ForestryPlugin { "###", "#S#", "###", '#', ForestryItem.stickImpregnated, 'S', Items.string); + RecipeUtil.addRecipe(ForestryItem.minecartBeehouse.getItemStack(), + "B", + "C", + 'B', ForestryBlock.apiculture.getItemStack(1, Constants.DEFINITION_BEEHOUSE_META), + 'C', Items.minecart); // FOOD STUFF if (ForestryItem.honeyedSlice.item() != null) { diff --git a/src/main/resources/assets/forestry/textures/items/cart.beehouse.png b/src/main/resources/assets/forestry/textures/items/cart.beehouse.png new file mode 100644 index 000000000..d220e1dcc Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/cart.beehouse.png differ