Files
2019-02-24 22:29:41 +08:00

162 lines
5.8 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/passive/AbstractHorse.java
+++ ../src-work/minecraft/net/minecraft/entity/passive/AbstractHorse.java
@@ -56,6 +56,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
public abstract class AbstractHorse extends EntityAnimal implements IInventoryChangedListener, IJumpingMount
{
@@ -66,7 +67,7 @@
return p_apply_1_ instanceof AbstractHorse && ((AbstractHorse)p_apply_1_).isBreeding();
}
};
- protected static final IAttribute JUMP_STRENGTH = (new RangedAttribute((IAttribute)null, "horse.jumpStrength", 0.7D, 0.0D, 2.0D)).setDescription("Jump Strength").setShouldWatch(true);
+ public static final IAttribute JUMP_STRENGTH = (new RangedAttribute((IAttribute)null, "horse.jumpStrength", 0.7D, 0.0D, 2.0D)).setDescription("Jump Strength").setShouldWatch(true);
private static final DataParameter<Byte> STATUS = EntityDataManager.<Byte>createKey(AbstractHorse.class, DataSerializers.BYTE);
private static final DataParameter<Optional<UUID>> OWNER_UNIQUE_ID = EntityDataManager.<Optional<UUID>>createKey(AbstractHorse.class, DataSerializers.OPTIONAL_UNIQUE_ID);
private int eatingCounter;
@@ -75,7 +76,7 @@
public int tailCounter;
public int sprintCounter;
protected boolean horseJumping;
- protected ContainerHorseChest horseChest;
+ public ContainerHorseChest horseChest;
protected int temper;
protected float jumpPower;
private boolean allowStandSliding;
@@ -88,6 +89,8 @@
protected boolean canGallop = true;
protected int gallopTime;
+ public int maxDomestication = 100; // CraftBukkit - store max domestication value
+
public AbstractHorse(World worldIn)
{
super(worldIn);
@@ -288,10 +291,10 @@
return 2;
}
- protected void initHorseChest()
+ public void initHorseChest()
{
ContainerHorseChest containerhorsechest = this.horseChest;
- this.horseChest = new ContainerHorseChest("HorseChest", this.getInventorySize());
+ this.horseChest = new ContainerHorseChest("HorseChest", this.getInventorySize(), this);
this.horseChest.setCustomName(this.getName());
if (containerhorsechest != null)
@@ -312,6 +315,7 @@
this.horseChest.addInventoryChangeListener(this);
this.updateHorseSlots();
+ this.itemHandler = new net.minecraftforge.items.wrapper.InvWrapper(this.horseChest);
}
protected void updateHorseSlots()
@@ -464,7 +468,7 @@
public int getMaxTemper()
{
- return 100;
+ return this.maxDomestication; // CraftBukkit - return stored max domestication instead of 100
}
protected float getSoundVolume()
@@ -544,7 +548,7 @@
if (this.getHealth() < this.getMaxHealth() && f > 0.0F)
{
- this.heal(f);
+ this.heal(f, EntityRegainHealthEvent.RegainReason.EATING);
flag = true;
}
@@ -608,7 +612,7 @@
public void onDeath(DamageSource cause)
{
- super.onDeath(cause);
+ // super.onDeath(cause); // Moved down
if (!this.world.isRemote && this.horseChest != null)
{
@@ -622,6 +626,7 @@
}
}
}
+ super.onDeath(cause);
}
public void onLivingUpdate()
@@ -637,7 +642,7 @@
{
if (this.rand.nextInt(900) == 0 && this.deathTime == 0)
{
- this.heal(1.0F);
+ this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN);
}
if (this.canEatGrass())
@@ -940,7 +945,7 @@
{
compound.setString("OwnerUUID", this.getOwnerUniqueId().toString());
}
-
+ compound.setInteger("Bukkit.MaxDomestication", this.maxDomestication);
if (!this.horseChest.getStackInSlot(0).isEmpty())
{
compound.setTag("SaddleItem", this.horseChest.getStackInSlot(0).writeToNBT(new NBTTagCompound()));
@@ -970,6 +975,9 @@
{
this.setOwnerUniqueId(UUID.fromString(s));
}
+ if (compound.hasKey("Bukkit.MaxDomestication")) {
+ this.maxDomestication = compound.getInteger("Bukkit.MaxDomestication");
+ }
IAttributeInstance iattributeinstance = this.getAttributeMap().getAttributeInstanceByName("Speed");
@@ -1073,6 +1081,16 @@
public void handleStartJump(int p_184775_1_)
{
+ float power;
+ if (p_184775_1_ >= 90) {
+ power = 1.0F;
+ } else {
+ power = 0.4F + 0.4F * (float) p_184775_1_ / 90.0F;
+ }
+ org.bukkit.event.entity.HorseJumpEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callHorseJumpEvent(this, power);
+ if (event.isCancelled()) {
+ return;
+ }
this.allowStandSliding = true;
this.makeHorseRear();
}
@@ -1227,4 +1245,22 @@
return livingdata;
}
+
+ // FORGE
+ private net.minecraftforge.items.IItemHandler itemHandler = null; // Initialized by initHorseChest above.
+
+ @SuppressWarnings("unchecked")
+ @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) itemHandler;
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ }
}