mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 03:59:45 +00:00
Fix desync causing hives to have no active bees
This commit is contained in:
1 parent
8f36c2a6fc
commit
ba313a9dfe
4 files changed
+42
-17
No files matched your search
@@ -9,6 +9,7 @@ import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -39,8 +40,7 @@ public interface IBeekeepingLogic extends INbtWritable, INbtReadable {
|
||||
/* CLIENT */
|
||||
|
||||
/**
|
||||
* Call this when the housing comes into view of the client.
|
||||
* (i.e. when {@link TileEntity#getUpdateTag()} is called)
|
||||
* Sync to client by using {@link #writeToNBT(NBTTagCompound)} in your {@link TileEntity#getUpdateTag()}
|
||||
*/
|
||||
void syncToClient();
|
||||
|
||||
|
||||
@@ -317,12 +317,13 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
|
||||
@Override
|
||||
public void formatDescriptionPacket(NBTTagCompound data) {
|
||||
writeToNBT(data);
|
||||
beekeepingLogic.syncToClient();
|
||||
beekeepingLogic.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeDescriptionPacket(NBTTagCompound data) {
|
||||
readFromNBT(data);
|
||||
beekeepingLogic.readFromNBT(data);
|
||||
}
|
||||
|
||||
/* IActivatable */
|
||||
|
||||
@@ -69,8 +69,15 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
beeLogic.syncToClient();
|
||||
return super.getUpdateTag();
|
||||
NBTTagCompound updateTag = super.getUpdateTag();
|
||||
beeLogic.writeToNBT(updateTag);
|
||||
return updateTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
|
||||
super.handleUpdateTag(tag);
|
||||
beeLogic.readFromNBT(tag);
|
||||
}
|
||||
|
||||
/* ICLIMATISED */
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.DamageSource;
|
||||
@@ -74,7 +75,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
@Nonnull
|
||||
private final IErrorLogic errorLogic;
|
||||
private IBee containedBee = null;
|
||||
private boolean active = true;
|
||||
private boolean active = false;
|
||||
private boolean angry = false;
|
||||
private int calmTime;
|
||||
|
||||
@@ -97,7 +98,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
}
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
if (!updatedLight && worldObj.getWorldTime() % 20 == 0) {
|
||||
if (!updatedLight && worldObj.getWorldTime() % 100 == 0) {
|
||||
updatedLight = worldObj.checkLightFor(EnumSkyBlock.BLOCK, getPos());
|
||||
}
|
||||
if (active && worldObj.rand.nextInt(4) == 0) {
|
||||
@@ -119,19 +120,13 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
attack(entity, 2);
|
||||
}
|
||||
beeLogic.doWork();
|
||||
setActive(true);
|
||||
} else {
|
||||
setActive(false);
|
||||
}
|
||||
} else {
|
||||
calmTime--;
|
||||
if (calmTime == 0) {
|
||||
setActive(true);
|
||||
} else {
|
||||
setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setActive(calmTime == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,8 +258,30 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
@Nullable
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket() {
|
||||
beeLogic.syncToClient();
|
||||
return super.getUpdatePacket();
|
||||
return new SPacketUpdateTileEntity(pos, 0, getUpdateTag());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
NBTTagCompound nbt = super.getUpdateTag();
|
||||
nbt.setBoolean("active", calmTime == 0);
|
||||
beeLogic.writeToNBT(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
|
||||
super.handleUpdateTag(tag);
|
||||
setActive(tag.getBoolean("active"));
|
||||
beeLogic.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
super.onDataPacket(net, pkt);
|
||||
NBTTagCompound nbt = pkt.getNbtCompound();
|
||||
handleUpdateTag(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user