diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpellbook.java b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpellbook.java index 73ef60bd..3e10d80b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpellbook.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpellbook.java @@ -30,6 +30,7 @@ public class EntitySpellbook extends EntityLiving implements IMagicals { public EntitySpellbook(World worldIn) { super(worldIn); setSize(0.6f, 0.6f); + enablePersistence(); } @Override @@ -77,15 +78,21 @@ public class EntitySpellbook extends EntityLiving implements IMagicals { this.isJumping = open && isInWater(); super.onUpdate(); if (open && world.isRemote) { + for (int offX = -2; offX <= 1; ++offX) { for (int offZ = -2; offZ <= 1; ++offZ) { - if (offX > -1 && offX < 1 && offZ == -1) offZ = 1; + if (offX > -1 && offX < 1 && offZ == -1) { + offZ = 1; + } + if (rand.nextInt(320) == 0) { for (int offY = 0; offY <= 1; ++offY) { - float vX = (float)offX/2 + rand.nextFloat(); - float vY = (float)offY/2 - rand.nextFloat() + 0.5f; - float vZ = (float)offZ/2 + rand.nextFloat(); - world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, posX, posY, posZ, vX, vY, vZ, new int[0]); + world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, + posX, posY, posZ, + offX/2F + rand.nextFloat(), + offY/2F - rand.nextFloat() + 0.5f, + offZ/2F + rand.nextFloat() + ); } } } @@ -94,13 +101,18 @@ public class EntitySpellbook extends EntityLiving implements IMagicals { if (world.rand.nextInt(30) == 0) { float celest = world.getCelestialAngle(1) * 4; + boolean isDay = celest > 3 || celest < 1; + Boolean userState = getUserSetState(); + boolean canToggle = (isDay != open) && (userState == null || userState == isDay); + if (canToggle) { setUserSetState(null); setIsOpen(isDay); } + if (userState != null && (isDay == open) && (userState == open)) { setUserSetState(null); } @@ -111,8 +123,11 @@ public class EntitySpellbook extends EntityLiving implements IMagicals { public boolean attackEntityFrom(DamageSource source, float amount) { if (!world.isRemote) { setDead(); + SoundType sound = SoundType.WOOD; + world.playSound(posX, posY, posZ, sound.getBreakSound(), SoundCategory.BLOCKS, sound.getVolume(), sound.getPitch(), true); + if (world.getGameRules().getBoolean("doTileDrops")) { entityDropItem(new ItemStack(UItems.spellbook), 0); } @@ -146,19 +161,18 @@ public class EntitySpellbook extends EntityLiving implements IMagicals { @Override public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); + setIsOpen(compound.getBoolean("open")); - if (compound.hasKey("force_open")) { - setUserSetState(compound.getBoolean("force_open")); - } else { - setUserSetState(null); - } + setUserSetState(compound.hasKey("force_open") ? compound.getBoolean("force_open") : null); } @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setBoolean("open", getIsOpen()); + Boolean state = getUserSetState(); + if (state != null) { compound.setBoolean("force_open", state); }