Skip to content

Commit

Permalink
Fixed sarcophagus sometimes not being openable after killing the phar…
Browse files Browse the repository at this point in the history
…aoh, when having unloaded the sarcophagus chunk. Closes #137
  • Loading branch information
GirafiStudios committed Aug 30, 2019
1 parent a591027 commit c961fed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
minecraft_version=1.12.2
forge_version=14.23.5.2836
mappings_version=stable_39
mod_version=2.0.12
mod_version=2.0.13
api_version=0.0.2
jei_version=4.15.0.283
hwyla_version=1.8.26-B41
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void setOpenable() {

public void spawn(EntityPlayer player, DifficultyInstance difficulty) {
if (!world.isRemote) {
EntityPharaoh pharaoh = new EntityPharaoh(world, true);
EntityPharaoh pharaoh = new EntityPharaoh(world);
pharaoh.onInitialSpawn(difficulty, null);
EnumFacing blockFacing = world.getBlockState(pos).getValue(BlockSarcophagus.FACING);
pharaoh.setLocationAndAngles(pos.getX(), pos.getY() + 1, pos.getZ(), blockFacing.getHorizontalAngle() + 90, 0.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class EntityPharaoh extends EntityUndeadBase {
private static final DataParameter<Integer> NUMERAL = EntityDataManager.createKey(EntityPharaoh.class, DataSerializers.VARINT);
private static final DataParameter<Optional<BlockPos>> SARCOPHAGUS_POS = EntityDataManager.createKey(EntityPharaoh.class, DataSerializers.OPTIONAL_BLOCK_POS);
private final BossInfoServer bossInfo = (BossInfoServer) new BossInfoServer(this.getDisplayName(), BossInfo.Color.YELLOW, BossInfo.Overlay.NOTCHED_10).setCreateFog(true);
private boolean hasSarcophagus;
private int stage;
private int suffixID = 0;
private int prefixID = 0;
Expand All @@ -73,18 +72,13 @@ public class EntityPharaoh extends EntityUndeadBase {
private String texturePath;

public EntityPharaoh(World world) {
this(world, false);
}

public EntityPharaoh(World world, boolean setSarcophagusPos) {
super(world);
this.setHealth(this.getMaxHealth());
this.isImmuneToFire = true;
this.experienceValue = 250;
this.hasSarcophagus = setSarcophagusPos;
this.stage = 0;
this.setCanPickUpLoot(false);
((PathNavigateGround)this.getNavigator()).setBreakDoors(true);
((PathNavigateGround) this.getNavigator()).setBreakDoors(true);
MinecraftForge.EVENT_BUS.register(this);
}

Expand Down Expand Up @@ -127,6 +121,7 @@ protected void entityInit() {
this.dataManager.register(PREFIX, 0);
this.dataManager.register(SUFFIX, 0);
this.dataManager.register(NUMERAL, 0);
this.dataManager.register(SARCOPHAGUS_POS, Optional.absent());
}

@Override
Expand All @@ -150,8 +145,9 @@ protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
@Override
@SideOnly(Side.CLIENT)
public String getTexture() {
if (this.texturePath == null)
if (this.texturePath == null) {
this.texturePath = new ResourceLocation(Constants.MOD_ID, "textures/entity/pharaoh_" + God.getGod(this.getVariant())) + ".png";
}
return this.texturePath;
}

Expand Down Expand Up @@ -184,7 +180,7 @@ private BlockPos getSarcophagusPos() {
}

public void setSarcophagusPos(BlockPos pos) {
this.dataManager.register(SARCOPHAGUS_POS, Optional.of(pos));
this.dataManager.set(SARCOPHAGUS_POS, Optional.fromNullable(pos));
}

@Override
Expand All @@ -198,7 +194,7 @@ protected void despawnEntity() {

@Override
public void onDeath(@Nonnull DamageSource source) {
if (this.hasSarcophagus) {
if (!world.isRemote) {
BlockPos sarcophagusPos = getSarcophagusPos();
if (sarcophagusPos != null) {
TileEntity tileEntity = world.getTileEntity(sarcophagusPos);
Expand Down Expand Up @@ -342,7 +338,7 @@ public void onUpdate() {
}

if (this.world.getDifficulty().getId() == 0) {
if (this.hasSarcophagus) {
if (this.getSarcophagusPos() != null) {
TileEntity te = world.getTileEntity(this.getSarcophagusPos());
if (te instanceof TileEntitySarcophagus) {
((TileEntitySarcophagus) te).hasSpawned = false;
Expand Down Expand Up @@ -380,13 +376,11 @@ public void writeEntityToNBT(NBTTagCompound compound) {
compound.setInteger("prefix", prefixID);
compound.setInteger("suffix", suffixID);
compound.setInteger("numeral", numID);
if (hasSarcophagus) {
BlockPos sarcophagusPos = getSarcophagusPos();
if (sarcophagusPos != null) {
compound.setInteger("sarcophagus_x", sarcophagusPos.getX());
compound.setInteger("sarcophagus_y", sarcophagusPos.getY());
compound.setInteger("sarcophagus_z", sarcophagusPos.getZ());
}
BlockPos sarcophagusPos = getSarcophagusPos();
if (sarcophagusPos != null) {
compound.setInteger("sarcophagus_x", sarcophagusPos.getX());
compound.setInteger("sarcophagus_y", sarcophagusPos.getY());
compound.setInteger("sarcophagus_z", sarcophagusPos.getZ());
}
}

Expand All @@ -396,15 +390,13 @@ public void readEntityFromNBT(NBTTagCompound compound) {
prefixID = compound.getInteger("prefix");
suffixID = compound.getInteger("suffix");
numID = compound.getInteger("numeral");
if (this.hasSarcophagus) {
if (compound.hasKey("sarcophagus_x")) {
int x = compound.getInteger("sarcophagus_x");
int y = compound.getInteger("sarcophagus_y");
int z = compound.getInteger("sarcophagus_z");
this.dataManager.set(SARCOPHAGUS_POS, Optional.of(new BlockPos(x, y, z)));
} else {
this.dataManager.set(SARCOPHAGUS_POS, Optional.absent());
}
if (compound.hasKey("sarcophagus_x")) {
int x = compound.getInteger("sarcophagus_x");
int y = compound.getInteger("sarcophagus_y");
int z = compound.getInteger("sarcophagus_z");
this.dataManager.set(SARCOPHAGUS_POS, Optional.of(new BlockPos(x, y, z)));
} else {
this.dataManager.set(SARCOPHAGUS_POS, Optional.absent());
}
this.setPharaohName(compound.getInteger("prefix"), compound.getInteger("suffix"), compound.getInteger("numeral"));
}
Expand Down

0 comments on commit c961fed

Please sign in to comment.