mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-18 19:39:06 +00:00
Added network event for updating bit flags.
Magic Apiary pulls charges from Aura Providers.
This commit is contained in:
1 parent
46cb2cb95a
commit
cb7b515626
7 files changed
+204
-24
No files matched your search
@@ -56,7 +56,7 @@ public class ContainerMagicApiary extends ContainerMB {
|
||||
j++;
|
||||
}
|
||||
|
||||
addPlayerInventory(inventoryPlayer, 0, 109);
|
||||
addPlayerInventory(inventoryPlayer, 0, 110);
|
||||
|
||||
maxSlot = currentSlot;
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.tileentity.TileEntityMagicApiary;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.tileentity.TileEntityMagicApiary;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiMagicApiary extends GuiContainer
|
||||
@@ -52,12 +55,15 @@ public class GuiMagicApiary extends GuiContainer
|
||||
private static final int MUTATIONBOOST_DEST_Y = 17;
|
||||
private static final int MUTATIONBOOST_SRC_X = 176;
|
||||
private static final int MUTATIONBOOST_SRC_Y = 71;
|
||||
|
||||
private GuiButton mutationButton;
|
||||
|
||||
public GuiMagicApiary(InventoryPlayer inventoryPlayer, TileEntityMagicApiary thaumicApiary) {
|
||||
super(new ContainerMagicApiary(inventoryPlayer, thaumicApiary));
|
||||
|
||||
this.xSize = WIDTH;
|
||||
this.ySize = HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +103,7 @@ public class GuiMagicApiary extends GuiContainer
|
||||
}
|
||||
|
||||
private void drawWorkBoostIcon(TileEntityMagicApiary apiary) {
|
||||
if (apiary.isWorkBoosted()) {
|
||||
if (apiary.isProductionBoosted()) {
|
||||
this.drawTexturedModalRect(this.guiLeft + WORKBOOST_DEST_X, this.guiTop + WORKBOOST_DEST_Y,
|
||||
WORKBOOST_SRC_X, WORKBOOST_SRC_Y, WORKBOOST_WIDTH, WORKBOOST_HEIGHT);
|
||||
}
|
||||
@@ -128,4 +134,10 @@ public class GuiMagicApiary extends GuiContainer
|
||||
return LIFEBAR_SRC_STAGE5_X;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_) {
|
||||
// TODO Auto-generated method stub
|
||||
super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package magicbees.main.utils.net;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.net.NetworkEventHandler.EventType;
|
||||
import magicbees.tileentity.ITileEntityFlags;
|
||||
|
||||
public class EventFlagsUpdate extends EventCoords {
|
||||
|
||||
private int[] flags;
|
||||
|
||||
public EventFlagsUpdate(ChunkCoords position, int[] flagValues) {
|
||||
super(EventType.FLAGS_UPDATE, position);
|
||||
flags = flagValues;
|
||||
}
|
||||
|
||||
public EventFlagsUpdate(DataInputStream byteStream) {
|
||||
super(EventType.FLAGS_UPDATE, byteStream);
|
||||
|
||||
this.readDataFromInputStream(byteStream);
|
||||
}
|
||||
|
||||
public int[] getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeDataToOutputStream(DataOutputStream byteStream) {
|
||||
super.writeDataToOutputStream(byteStream);
|
||||
|
||||
try {
|
||||
byteStream.writeByte(flags.length);
|
||||
for (int index = 0; index < flags.length; ++index) {
|
||||
byteStream.writeInt(flags[index]);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LogHelper.error("Could not write EventFlagsUpdate data to stream.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDataFromInputStream(DataInputStream byteStream) {
|
||||
super.readDataFromInputStream(byteStream);
|
||||
|
||||
try {
|
||||
byte length = byteStream.readByte();
|
||||
|
||||
this.flags = new int[length];
|
||||
for (int index = 0; index < length; ++index) {
|
||||
flags[index] = byteStream.readInt();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LogHelper.error("Could not read EventFlagsUpdate data from stream.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(EntityPlayerMP player) {
|
||||
TileEntity tile = FMLClientHandler.instance().getClient().theWorld.getTileEntity(getCoords().x, getCoords().y, getCoords().z);
|
||||
|
||||
if (tile != null && tile instanceof ITileEntityFlags) {
|
||||
((ITileEntityFlags) tile).setFlags(this.flags);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import io.netty.buffer.ByteBufInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import magicbees.main.MagicBees;
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.VersionInfo;
|
||||
@@ -26,9 +27,14 @@ public class NetworkEventHandler {
|
||||
|
||||
public static final String CHANNEL_NAME = VersionInfo.ModName;
|
||||
|
||||
public static NetworkEventHandler getInstance() {
|
||||
return MagicBees.object.netHandler;
|
||||
}
|
||||
|
||||
public enum EventType {
|
||||
UNKNOWN,
|
||||
INVENTORY_UPDATE,
|
||||
FLAGS_UPDATE,
|
||||
;
|
||||
}
|
||||
|
||||
@@ -56,6 +62,13 @@ public class NetworkEventHandler {
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
public void sendFlagsUpdate(TileEntity entity, int[] flags) {
|
||||
EventFlagsUpdate event = new EventFlagsUpdate(new ChunkCoords(entity), flags);
|
||||
FMLProxyPacket packet = event.getPacket();
|
||||
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
private void sendPacket(FMLProxyPacket packet) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
channel.sendToAll(packet);
|
||||
@@ -85,6 +98,10 @@ public class NetworkEventHandler {
|
||||
EventInventoryUpdate eventData = new EventInventoryUpdate(data);
|
||||
eventData.process(player);
|
||||
}
|
||||
else if (eventId == EventType.FLAGS_UPDATE.ordinal()) {
|
||||
EventFlagsUpdate eventData = new EventFlagsUpdate(data);
|
||||
eventData.process(player);
|
||||
}
|
||||
else {
|
||||
throw new InvalidEventTypeIndexException("");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
public interface ITileEntityFlags {
|
||||
|
||||
public void setFlags(int[] flags);
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import magicbees.main.MagicBees;
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.ItemStackUtils;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.net.EventFlagsUpdate;
|
||||
import magicbees.main.utils.net.NetworkEventHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -33,7 +35,7 @@ import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileEntityMagicApiary extends TileEntity implements ISidedInventory, IBeeHousing {
|
||||
public class TileEntityMagicApiary extends TileEntity implements ISidedInventory, IBeeHousing, ITileEntityFlags {
|
||||
|
||||
public static final String tileEntityName = CommonProxy.DOMAIN + ".magicApiary";
|
||||
private GameProfile ownerProfile;
|
||||
@@ -47,9 +49,11 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
private static final int SLOT_PRODUCTS_COUNT = 7;
|
||||
|
||||
private static final int AURAPROVIDER_SEARCH_RADIUS = 6;
|
||||
private static int CHARGE_TIME_MUTATION = 240;
|
||||
private static int CHARGE_TIME_DEATH = 80;
|
||||
private static int CHARGE_TIME_PRODUCTION = 60;
|
||||
|
||||
private IBeekeepingLogic logic;
|
||||
private boolean hasAuraProvider = false;
|
||||
private IMagicApiaryAuraProvider auraProvider;
|
||||
private ChunkCoords auraProviderPosition;
|
||||
private BiomeGenBase biome;
|
||||
@@ -57,9 +61,13 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
private int displayHealth = 0;
|
||||
private boolean init = false;
|
||||
|
||||
private static final int FLAG_MUTATIONCHARGE = 1 << 0;
|
||||
private static final int FLAG_DEATHCHARGE = 1 << 1;
|
||||
private static final int FLAG_PRODUCTION = 1 << 2;
|
||||
private static final int OFFSET_MUTATION = 0;
|
||||
private static final int OFFSET_DEATH = 1;
|
||||
private static final int OFFSET_PRODUCTION = 2;
|
||||
private static final int FLAG_MUTATIONCHARGE = 1 << OFFSET_MUTATION;
|
||||
private static final int FLAG_DEATHCHARGE = 1 << OFFSET_DEATH;
|
||||
private static final int FLAG_PRODUCTIONCHARGE = 1 << OFFSET_PRODUCTION;
|
||||
private long[] chargeTimestamps = new long[3];
|
||||
private int flags;
|
||||
|
||||
private IErrorState errorState = ErrorStateRegistry.getErrorState("ok");
|
||||
@@ -196,7 +204,7 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
mod *= ((IHiveFrame) getStackInSlot(slotIndex).getItem()).getProductionModifier(genome, mod);
|
||||
}
|
||||
}
|
||||
if (this.isWorkBoosted()) {
|
||||
if (this.isProductionBoosted()) {
|
||||
mod = mod * 2f;
|
||||
}
|
||||
return mod;
|
||||
@@ -506,6 +514,9 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
ChunkCoords.writeToNBT(this.auraProviderPosition, compound);
|
||||
|
||||
compound.setInteger("flags", this.flags);
|
||||
compound.setLong("timestamp0", chargeTimestamps[0]);
|
||||
compound.setLong("timestamp1", chargeTimestamps[1]);
|
||||
compound.setLong("timestamp2", chargeTimestamps[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -529,6 +540,9 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
|
||||
this.auraProviderPosition = ChunkCoords.readFromNBT(compound);
|
||||
this.flags = compound.getInteger("flags");
|
||||
this.chargeTimestamps[0] = compound.getLong("timestamp0");
|
||||
this.chargeTimestamps[1] = compound.getLong("timestamp1");
|
||||
this.chargeTimestamps[2] = compound.getLong("timestamp2");
|
||||
}
|
||||
|
||||
public float getExactTemperature() {
|
||||
@@ -576,7 +590,7 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
}
|
||||
|
||||
public void updateServerSide() {
|
||||
if (!this.hasAuraProvider) {
|
||||
if (this.auraProvider == null) {
|
||||
findAuraProvider();
|
||||
}
|
||||
else {
|
||||
@@ -618,20 +632,65 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
iCrafting.sendProgressBarUpdate(container, 1, logic.getTotalBreedingTime());
|
||||
}
|
||||
|
||||
public boolean isWorkBoosted() {
|
||||
return false;
|
||||
public boolean isProductionBoosted() {
|
||||
return (flags & FLAG_PRODUCTIONCHARGE) == FLAG_PRODUCTIONCHARGE;
|
||||
}
|
||||
|
||||
public boolean isDeathRateBoosted() {
|
||||
return false;
|
||||
return (flags & FLAG_DEATHCHARGE) == FLAG_DEATHCHARGE;
|
||||
}
|
||||
|
||||
public boolean isMutationBoosted() {
|
||||
return false;
|
||||
return (flags & FLAG_MUTATIONCHARGE) == FLAG_MUTATIONCHARGE;
|
||||
}
|
||||
|
||||
private void updateAuraProvider() {
|
||||
int oldFlags = flags;
|
||||
if (!isMutationBoosted()) {
|
||||
if (this.auraProvider.getMutationCharge()) {
|
||||
flags |= FLAG_MUTATIONCHARGE;
|
||||
chargeTimestamps[OFFSET_MUTATION] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (chargeTimestamps[OFFSET_MUTATION] + CHARGE_TIME_MUTATION <= worldObj.getTotalWorldTime()) {
|
||||
if (!this.auraProvider.getMutationCharge()) {
|
||||
flags = flags & ~FLAG_MUTATIONCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDeathRateBoosted()) {
|
||||
if (this.auraProvider.getDeathRateCharge()) {
|
||||
flags |= FLAG_DEATHCHARGE;
|
||||
chargeTimestamps[OFFSET_DEATH] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (chargeTimestamps[OFFSET_DEATH] + CHARGE_TIME_DEATH <= worldObj.getTotalWorldTime()) {
|
||||
if (!this.auraProvider.getDeathRateCharge()) {
|
||||
flags = flags & ~FLAG_DEATHCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isProductionBoosted()) {
|
||||
if (this.auraProvider.getProductionCharge()) {
|
||||
flags |= FLAG_PRODUCTIONCHARGE;
|
||||
chargeTimestamps[OFFSET_PRODUCTION] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (chargeTimestamps[OFFSET_PRODUCTION] + CHARGE_TIME_PRODUCTION <= worldObj.getTotalWorldTime()) {
|
||||
if (!this.auraProvider.getProductionCharge()) {
|
||||
flags = flags & ~FLAG_PRODUCTIONCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oldFlags != flags) {
|
||||
NetworkEventHandler.getInstance().sendFlagsUpdate(this, new int[] {flags});
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MAX_BLOCKS_SEARCH_PER_CHECK = (AURAPROVIDER_SEARCH_RADIUS * 2 + 1) * 2;
|
||||
@@ -650,10 +709,13 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
else {
|
||||
// Will end up here after loading from save with a valid auraProvider.
|
||||
if (locationHasAuraProvider(auraProviderPosition.x, auraProviderPosition.y, auraProviderPosition.z)) {
|
||||
this.auraProvider = (IMagicApiaryAuraProvider)(worldObj.getTileEntity(auraProviderPosition.x,
|
||||
IMagicApiaryAuraProvider provider = (IMagicApiaryAuraProvider)(worldObj.getTileEntity(auraProviderPosition.x,
|
||||
auraProviderPosition.y,
|
||||
auraProviderPosition.x));
|
||||
this.hasAuraProvider = true;
|
||||
if (provider == null) {
|
||||
// ... well, it WAS here...
|
||||
this.auraProviderPosition = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -668,7 +730,6 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
if (locationHasAuraProvider(x, y, z)) {
|
||||
LogHelper.info("Apiary found aura provider!");
|
||||
this.auraProvider = (IMagicApiaryAuraProvider)(worldObj.getTileEntity(x, y, z));
|
||||
this.hasAuraProvider = true;
|
||||
saveAuraProviderPosition(x, y, z);
|
||||
return;
|
||||
}
|
||||
@@ -711,4 +772,11 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(int[] flagArray) {
|
||||
if (flagArray.length == 1) {
|
||||
this.flags = flagArray[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user