Skip to content

Commit f954f26

Browse files
committed
Fixed ice dragon egg disappearing when reloading the chunk/ server client sync issues. Fixes #3809
Fixed frozen ice dragon egg tile entity not spawning an egg when broken Fixed hearts appearing when attacking a dragon egg. Fixes #4479 Fixed age value for dragon eggs being stored as bytes
1 parent e7b654f commit f954f26

File tree

4 files changed

+54
-45
lines changed

4 files changed

+54
-45
lines changed

src/main/java/com/github/alexthe666/iceandfire/block/BlockEggInIce.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,16 @@ public BlockRenderType getRenderType(BlockState state) {
4949

5050
@Override
5151
public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, TileEntity te, ItemStack stack) {
52+
player.addStat(Stats.BLOCK_MINED.get(this));
53+
player.addExhaustion(0.005F);
54+
}
55+
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
5256
if (worldIn.getTileEntity(pos) != null) {
5357
if (worldIn.getTileEntity(pos) instanceof TileEntityEggInIce) {
5458
TileEntityEggInIce tile = (TileEntityEggInIce) worldIn.getTileEntity(pos);
5559
tile.spawnEgg();
5660
}
5761
}
58-
player.addStat(Stats.BLOCK_MINED.get(this));
59-
player.addExhaustion(0.005F);
6062
}
6163

62-
@SuppressWarnings("deprecation")
63-
public boolean isOpaqueCube(BlockState blockstate) {
64-
return false;
65-
}
66-
67-
@SuppressWarnings("deprecation")
68-
public boolean isFullCube(BlockState blockstate) {
69-
return false;
70-
}
7164
}

src/main/java/com/github/alexthe666/iceandfire/entity/DragonType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public void updateEggCondition(EntityDragonEgg egg) {
9494
}
9595
if (this == ICE) {
9696
if (egg.world.getBlockState(pos).getMaterial() == Material.WATER && egg.getRNG().nextInt(500) == 0) {
97-
egg.remove();
9897
egg.world.setBlockState(pos, IafBlockRegistry.EGG_IN_ICE.getDefaultState());
9998
egg.world.playSound(egg.getPosX(), egg.getPosY() + egg.getEyeHeight(), egg.getPosZ(), SoundEvents.BLOCK_GLASS_BREAK, egg.getSoundCategory(), 2.5F, 1.0F, false);
10099
if (egg.world.getBlockState(pos).getBlock() instanceof BlockEggInIce) {
101100
((TileEntityEggInIce) egg.world.getTileEntity(pos)).type = egg.getEggType();
102101
((TileEntityEggInIce) egg.world.getTileEntity(pos)).ownerUUID = egg.getOwnerId();
103102
}
103+
egg.remove();
104104
}
105105
}
106106
if (this == LIGHTNING) {

src/main/java/com/github/alexthe666/iceandfire/entity/EntityDragonEgg.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static AttributeModifierMap.MutableAttribute bakeAttributes() {
5454
public void writeAdditional(CompoundNBT tag) {
5555
super.writeAdditional(tag);
5656
tag.putInt("Color", (byte) this.getEggType().ordinal());
57-
tag.putByte("DragonAge", (byte) this.getDragonAge());
57+
tag.putInt("DragonAge", this.getDragonAge());
5858
try{
5959
if (this.getOwnerId() == null) {
6060
tag.putString("OwnerUUID", "");
@@ -70,7 +70,7 @@ public void writeAdditional(CompoundNBT tag) {
7070
public void readAdditional(CompoundNBT tag) {
7171
super.readAdditional(tag);
7272
this.setEggType(EnumDragonEgg.values()[tag.getInt("Color")]);
73-
this.setDragonAge(tag.getByte("DragonAge"));
73+
this.setDragonAge(tag.getInt("DragonAge"));
7474
String s;
7575

7676
if (tag.contains("OwnerUUID", 8)) {
@@ -126,8 +126,10 @@ public void setDragonAge(int i) {
126126
@Override
127127
public void tick() {
128128
super.tick();
129-
this.setAir(200);
130-
getEggType().dragonType.updateEggCondition(this);
129+
if (!world.isRemote()) {
130+
this.setAir(200);
131+
getEggType().dragonType.updateEggCondition(this);
132+
}
131133
}
132134

133135
@Override
@@ -156,7 +158,7 @@ public boolean attackEntityFrom(DamageSource var1, float var2) {
156158
this.entityDropItem(this.getItem().getItem(), 1);
157159
}
158160
this.remove();
159-
return super.attackEntityFrom(var1, var2);
161+
return true;
160162
}
161163

162164
private ItemStack getItem() {

src/main/java/com/github/alexthe666/iceandfire/entity/tile/TileEntityEggInIce.java

+42-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package com.github.alexthe666.iceandfire.entity.tile;
22

3-
import java.util.UUID;
4-
import java.util.concurrent.ThreadLocalRandom;
5-
6-
import javax.annotation.Nullable;
7-
83
import com.github.alexthe666.iceandfire.IafConfig;
94
import com.github.alexthe666.iceandfire.entity.EntityDragonEgg;
105
import com.github.alexthe666.iceandfire.entity.EntityIceDragon;
116
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
127
import com.github.alexthe666.iceandfire.enums.EnumDragonEgg;
13-
148
import net.minecraft.block.BlockState;
159
import net.minecraft.block.Blocks;
1610
import net.minecraft.nbt.CompoundNBT;
@@ -20,6 +14,10 @@
2014
import net.minecraft.tileentity.ITickableTileEntity;
2115
import net.minecraft.tileentity.TileEntity;
2216

17+
import javax.annotation.Nullable;
18+
import java.util.UUID;
19+
import java.util.concurrent.ThreadLocalRandom;
20+
2321
public class TileEntityEggInIce extends TileEntity implements ITickableTileEntity {
2422
public EnumDragonEgg type;
2523
public int age;
@@ -35,6 +33,7 @@ public TileEntityEggInIce() {
3533

3634
@Override
3735
public CompoundNBT write(CompoundNBT tag) {
36+
super.write(tag);
3837
if (type != null) {
3938
tag.putByte("Color", (byte) type.ordinal());
4039
} else {
@@ -44,43 +43,58 @@ public CompoundNBT write(CompoundNBT tag) {
4443
if (ownerUUID == null) {
4544
tag.putString("OwnerUUID", "");
4645
} else {
47-
tag.putString("OwnerUUID", ownerUUID.toString());
46+
tag.putUniqueId("OwnerUUID", ownerUUID);
4847
}
49-
50-
return super.write(tag);
48+
return tag;
5149
}
5250

5351
@Override
5452
public void read(BlockState state, CompoundNBT tag) {
5553
super.read(state,tag);
5654
type = EnumDragonEgg.values()[tag.getByte("Color")];
57-
age = tag.getByte("Age");
58-
UUID s;
55+
age = tag.getInt("Age");
56+
UUID s = null;
5957

6058
if (tag.hasUniqueId("OwnerUUID")) {
6159
s = tag.getUniqueId("OwnerUUID");
6260
} else {
63-
String s1 = tag.getString("OwnerUUID");
64-
s = PreYggdrasilConverter.convertMobOwnerIfNeeded(this.world.getServer(), s1);
61+
try {
62+
String s1 = tag.getString("OwnerUUID");
63+
s = PreYggdrasilConverter.convertMobOwnerIfNeeded(this.world.getServer(), s1);
64+
}
65+
catch (Exception ignored) { }
6566
}
6667
if (s != null) {
6768
ownerUUID = s;
6869
}
6970
}
7071

7172
@Override
72-
public SUpdateTileEntityPacket getUpdatePacket() {
73-
return new SUpdateTileEntityPacket(pos, 1, getUpdateTag());
73+
public void handleUpdateTag(BlockState blockState, CompoundNBT parentNBTTagCompound)
74+
{
75+
this.read(blockState, parentNBTTagCompound);
76+
}
77+
78+
public CompoundNBT getUpdateTag()
79+
{
80+
CompoundNBT nbtTagCompound = new CompoundNBT();
81+
write(nbtTagCompound);
82+
return nbtTagCompound;
7483
}
7584

7685
@Override
77-
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket packet) {
78-
read(this.getBlockState(), packet.getNbtCompound());
86+
@Nullable
87+
public SUpdateTileEntityPacket getUpdatePacket()
88+
{
89+
CompoundNBT nbtTagCompound = new CompoundNBT();
90+
write(nbtTagCompound);
91+
return new SUpdateTileEntityPacket(this.pos, -1, nbtTagCompound);
7992
}
8093

8194
@Override
82-
public CompoundNBT getUpdateTag() {
83-
return this.write(new CompoundNBT());
95+
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
96+
BlockState blockState = world.getBlockState(pos);
97+
read(blockState, pkt.getNbtCompound()); // read from the nbt in the packet
8498
}
8599

86100
public void spawnEgg() {
@@ -99,18 +113,18 @@ public void spawnEgg() {
99113
public void tick() {
100114
age++;
101115
if (age >= IafConfig.dragonEggTime && type != null && !spawned) {
102-
world.destroyBlock(pos, false);
103-
world.setBlockState(pos, Blocks.WATER.getDefaultState());
104-
EntityIceDragon dragon = new EntityIceDragon(world);
105-
dragon.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
106-
dragon.setVariant(type.ordinal() - 4);
107-
dragon.setGender(ThreadLocalRandom.current().nextBoolean());
108-
dragon.setTamed(true);
109-
dragon.setHunger(50);
110-
dragon.setOwnerId(ownerUUID);
111116
if (!world.isRemote) {
117+
EntityIceDragon dragon = new EntityIceDragon(world);
118+
dragon.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
119+
dragon.setVariant(type.ordinal() - 4);
120+
dragon.setGender(ThreadLocalRandom.current().nextBoolean());
121+
dragon.setTamed(true);
122+
dragon.setHunger(50);
123+
dragon.setOwnerId(ownerUUID);
112124
world.addEntity(dragon);
113125
spawned = true;
126+
world.destroyBlock(pos, false);
127+
world.setBlockState(pos, Blocks.WATER.getDefaultState());
114128
}
115129

116130
}

0 commit comments

Comments
 (0)