Files
Purpur/patches/server/0039-Cows-eat-mushrooms.patch
BillyGalbreath d93887a156 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
5b20df6bf added PlayerNameEntityEvent
ff9c82444 Add worldborder events
616b1f3cd consider enchants for destroy speed
aaef1d5cc fix file conversion
674d8f7f7 Make discovered maps config work in treasure maps from loot tables too
be1687914 stop firing pressure plate EntityInteractEvent for ignored entities (fixes #4962)
7d56f38ed Do not use the bukkit singleton for the GUI (Fixes #5301)
4c9bdf53a Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5299)
8647bd130 Improve ServerGUI
fcc6d3359 Throw proper exception on empty JsonList file
17d2e1291 Fix interact event in adventure mode
964e0bf42 MC-29274: Fix Wither hostility towards players
9e24a5213 Fixed furnace cook-speed multiplier losing precision when calculating cook time
c7e42faa3 Do not create unnecessary copies of the passenger list
40881ad67 added tnt minecarts to the tnt height nerf
26be708f4 Remove streams from SensorNearest
5b5989b21 fix nullability of playerlist header/footer, closes #5290
45bc531dd Fix Material#getTranslationKey for Block Materials (#5294)
2021-03-04 21:45:44 -06:00

141 lines
7.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sat, 4 May 2019 01:10:30 -0500
Subject: [PATCH] Cows eat mushrooms
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 6282e02c063e3b72889d85bbf3a5e0ca17919a02..1d97191217f568681b6507027c2113b2a15f3569 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2778,6 +2778,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.invulnerable = flag;
}
+ public void copyPositionRotation(Entity entity) { this.u(entity); } // Purpur - OBFHELPER
public void u(Entity entity) {
this.setPositionRotation(entity.locX(), entity.locY(), entity.locZ(), entity.yaw, entity.pitch);
}
diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java
index 42e6761c8b18b79ffd3f4d5e853ea87a2c153c23..cfb009c811bd2908d38da1b0007cb7aaed4e42c3 100644
--- a/src/main/java/net/minecraft/server/EntityCow.java
+++ b/src/main/java/net/minecraft/server/EntityCow.java
@@ -16,6 +16,7 @@ public class EntityCow extends EntityAnimal {
this.goalSelector.a(0, new PathfinderGoalFloat(this));
this.goalSelector.a(1, new PathfinderGoalPanic(this, 2.0D));
this.goalSelector.a(2, new PathfinderGoalBreed(this, 1.0D));
+ if (world.purpurConfig.cowFeedMushrooms > 0) this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.25D, RecipeItemStack.a(Items.WHEAT, Blocks.RED_MUSHROOM.getItem(), Blocks.BROWN_MUSHROOM.getItem()), false)); else // Purpur
this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.25D, RecipeItemStack.a(Items.WHEAT), false));
this.goalSelector.a(4, new PathfinderGoalFollowParent(this, 1.25D));
this.goalSelector.a(5, new PathfinderGoalRandomStrollLand(this, 1.0D));
@@ -70,11 +71,80 @@ public class EntityCow extends EntityAnimal {
entityhuman.a(enumhand, itemstack1);
return EnumInteractionResult.a(this.world.isClientSide);
+ // Purpur start - feed mushroom to change to mooshroom
+ } else if (world.purpurConfig.cowFeedMushrooms > 0 && getEntityType() != EntityTypes.MOOSHROOM && isMushroom(itemstack)) {
+ return feedMushroom(entityhuman, itemstack);
+ // Purpur end
} else {
return super.b(entityhuman, enumhand);
}
}
+ // Purpur start - feed mushroom to change to mooshroom
+ private int redMushroomsFed = 0;
+ private int brownMushroomsFed = 0;
+
+ private boolean isMushroom(ItemStack itemstack) {
+ return itemstack.getItem() == Blocks.RED_MUSHROOM.getItem() || itemstack.getItem() == Blocks.BROWN_MUSHROOM.getItem();
+ }
+
+ private int incrementFeedCount(ItemStack itemstack) {
+ if (itemstack.getItem() == Blocks.RED_MUSHROOM.getItem()) {
+ return ++redMushroomsFed;
+ } else {
+ return ++brownMushroomsFed;
+ }
+ }
+
+ private EnumInteractionResult feedMushroom(EntityHuman entityhuman, ItemStack itemstack) {
+ world.broadcastEntityEffect(this, (byte) 18); // hearts
+ playSound(SoundEffects.ENTITY_COW_MILK, 1.0F, 1.0F);
+ if (incrementFeedCount(itemstack) < world.purpurConfig.cowFeedMushrooms) {
+ if (!entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ }
+ return EnumInteractionResult.CONSUME; // require 5 mushrooms to transform (prevents mushroom duping)
+ }
+ EntityMushroomCow mooshroom = EntityTypes.MOOSHROOM.create(world);
+ if (mooshroom == null) {
+ return EnumInteractionResult.PASS;
+ }
+ if (itemstack.getItem() == Blocks.BROWN_MUSHROOM.getItem()) {
+ mooshroom.setVariant(EntityMushroomCow.Type.BROWN);
+ } else {
+ mooshroom.setVariant(EntityMushroomCow.Type.RED);
+ }
+ mooshroom.setPositionRotation(this.locX(), this.locY(), this.locZ(), this.yaw, this.pitch);
+ mooshroom.setHealth(this.getHealth());
+ mooshroom.setAge(getAge());
+ mooshroom.copyPositionRotation(this);
+ mooshroom.setRenderYawOffset(this.getRenderYawOffset());
+ mooshroom.setHeadRotation(this.getHeadRotation());
+ mooshroom.lastYaw = this.lastYaw;
+ mooshroom.lastPitch = this.lastPitch;
+ if (this.hasCustomName()) {
+ mooshroom.setCustomName(this.getCustomName());
+ }
+ if (CraftEventFactory.callEntityTransformEvent(this, mooshroom, org.bukkit.event.entity.EntityTransformEvent.TransformReason.INFECTION).isCancelled()) {
+ return EnumInteractionResult.PASS;
+ }
+ if (!new com.destroystokyo.paper.event.entity.EntityTransformedEvent(this.getBukkitEntity(), mooshroom.getBukkitEntity(), com.destroystokyo.paper.event.entity.EntityTransformedEvent.TransformedReason.INFECTED).callEvent()) {
+ return EnumInteractionResult.PASS;
+ }
+ this.world.addEntity(mooshroom);
+ this.die();
+ if (!entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ }
+ for (int i = 0; i < 15; ++i) {
+ ((WorldServer) world).sendParticles(((WorldServer) world).players, null, Particles.HAPPY_VILLAGER,
+ locX() + random.nextFloat(), locY() + (random.nextFloat() * 2), locZ() + random.nextFloat(), 1,
+ random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, 0, true);
+ }
+ return EnumInteractionResult.SUCCESS;
+ }
+ // Purpur end
+
@Override
public EntityCow createChild(WorldServer worldserver, EntityAgeable entityageable) {
return (EntityCow) EntityTypes.COW.a((World) worldserver);
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 996242d7c62984b67b9443356c509d0c7c85e33a..8cc440e0e7108e2c7ca29b2f8a2fc5a723dcef0d 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -81,7 +81,7 @@ public abstract class EntityLiving extends Entity {
public int maxNoDamageTicks;
public final float ay;
public final float az;
- public float aA;
+ public float aA; public float getRenderYawOffset() { return this.aA; } public void setRenderYawOffset(float f) { this.aA = f; } // Purpur - OBFHELPER
public float aB;
public float aC;
public float aD;
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 9c5de125a6ed207f238dff1e17e38a4083c4c251..0c841b824a93d5e43bad171d1ca828eca3e891df 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -132,6 +132,11 @@ public class PurpurWorldConfig {
chickenRetaliate = getBoolean("mobs.chicken.retaliate", chickenRetaliate);
}
+ public int cowFeedMushrooms = 0;
+ private void cowSettings() {
+ cowFeedMushrooms = getInt("mobs.cow.feed-mushrooms-for-mooshroom", cowFeedMushrooms);
+ }
+
public double creeperChargedChance = 0.0D;
private void creeperSettings() {
creeperChargedChance = getDouble("mobs.creeper.naturally-charged-chance", creeperChargedChance);