Sync tile entities with casters properly, and tidy up a few other related things

This commit is contained in:
Electroblob77
2020-05-24 22:09:09 +01:00
parent e17b5d2300
commit 94f4e680af
8 changed files with 35 additions and 26 deletions
@@ -89,7 +89,10 @@ public class ForestOfThorns extends Spell {
if(tileentity instanceof TileEntityPlayerSaveTimed){
((TileEntityPlayerSaveTimed)tileentity).setLifetime((int)(getProperty(DURATION).floatValue()
* modifiers.get(WizardryItems.duration_upgrade)));
if(caster != null) ((TileEntityPlayerSaveTimed)tileentity).setCaster(caster);
if(caster != null){
((TileEntityPlayerSaveTimed)tileentity).setCaster(caster);
}
((TileEntityPlayerSaveTimed)tileentity).sync();
}
}
}
@@ -32,8 +32,10 @@ public class Snare extends SpellRay {
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){
if(side == EnumFacing.UP && world.isSideSolid(pos, EnumFacing.UP) && WizardryUtilities.canBlockBeReplaced(world, pos.up())){
world.setBlockState(pos.up(), WizardryBlocks.snare.getDefaultState());
((TileEntityPlayerSave)world.getTileEntity(pos.up())).setCaster(caster);
if(!world.isRemote){
world.setBlockState(pos.up(), WizardryBlocks.snare.getDefaultState());
((TileEntityPlayerSave)world.getTileEntity(pos.up())).setCaster(caster);
}
return true;
}
@@ -237,7 +237,7 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), this.getUpdateTag());
return new SPacketUpdateTileEntity(pos, 0, this.getUpdateTag());
}
@Override
@@ -3,7 +3,6 @@ package electroblob.wizardry.tileentity;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.block.BlockBookshelf;
import electroblob.wizardry.inventory.ContainerBookshelf;
import electroblob.wizardry.item.ItemSpellBook;
import electroblob.wizardry.util.NBTExtras;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -181,7 +180,7 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), this.getUpdateTag());
return new SPacketUpdateTileEntity(pos, 0, this.getUpdateTag());
}
@Override
@@ -87,7 +87,7 @@ public class TileEntityLectern extends TileEntity implements ITickable {
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), this.getUpdateTag());
return new SPacketUpdateTileEntity(pos, 0, this.getUpdateTag());
}
@Override
@@ -5,6 +5,8 @@ import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nullable;
@@ -19,6 +21,11 @@ public class TileEntityPlayerSave extends TileEntity {
public TileEntityPlayerSave(){}
/** Called to manually sync the tile entity with clients. */
public void sync(){
this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound){
super.readFromNBT(tagCompound);
@@ -57,6 +64,22 @@ public class TileEntityPlayerSave extends TileEntity {
public void setCaster(@Nullable EntityLivingBase caster){
this.casterUUID = caster == null ? null : caster.getUniqueID();
this.sync();
}
@Override
public final NBTTagCompound getUpdateTag(){
return this.writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
return new SPacketUpdateTileEntity(pos, 0, this.getUpdateTag());
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
readFromNBT(pkt.getNbtCompound());
}
}
@@ -48,22 +48,4 @@ public class TileEntityPlayerSaveTimed extends TileEntityPlayerSave implements I
return tagCompound;
}
@Override
public final NBTTagCompound getUpdateTag(){
return this.writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new SPacketUpdateTileEntity(pos, 1, tag);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
NBTTagCompound tag = pkt.getNbtCompound();
readFromNBT(tag);
}
}
@@ -50,7 +50,7 @@ public class TileEntityReceptacle extends TileEntity {
@Nullable
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), this.getUpdateTag());
return new SPacketUpdateTileEntity(pos, 0, this.getUpdateTag());
}
@Override