Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compat with FFAPI and Connector #2842

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
import com.google.gson.JsonElement;
import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.util.Either;
@@ -40,6 +_,7 @@
@@ -40,12 +_,9 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
-import java.util.function.BooleanSupplier;
-import java.util.function.Consumer;
-import java.util.function.IntFunction;
-import java.util.function.IntSupplier;
-import java.util.function.Supplier;
+import java.util.function.*;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.minecraft.CrashReport;
@@ -75,7 +_,6 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
Expand Down Expand Up @@ -88,24 +95,27 @@
}

this.m_140258_(p_203002_);
@@ -685,7 +_,21 @@
@@ -685,7 +_,24 @@

private static void m_143064_(ServerLevel p_143065_, List<CompoundTag> p_143066_) {
if (!p_143066_.isEmpty()) {
- p_143065_.m_143327_(EntityType.m_147045_(p_143066_, p_143065_));
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
+ p_143065_.m_143327_(EntityType.m_147045_(p_143066_, p_143065_).filter((entity) -> {
+ boolean needsRemoval = false;
+ net.minecraft.server.dedicated.DedicatedServer server = p_143065_.getCraftServer().getServer();
+ if (!server.m_6997_() && entity instanceof net.minecraft.world.entity.npc.Npc) {
+ entity.m_146870_();
+ needsRemoval = true;
+ }
+ if (!server.m_6998_() && (entity instanceof net.minecraft.world.entity.animal.Animal || entity instanceof net.minecraft.world.entity.animal.WaterAnimal)) {
+ entity.m_146870_();
+ needsRemoval = true;
+ p_143065_.m_143327_(EntityType.m_147045_(p_143066_, p_143065_).filter(new Predicate<Entity>() {
+ @Override
+ public boolean test(Entity entity) {
+ boolean needsRemoval = false;
+ net.minecraft.server.dedicated.DedicatedServer server = p_143065_.getCraftServer().getServer();
+ if (!server.m_6997_() && entity instanceof net.minecraft.world.entity.npc.Npc) {
+ entity.m_146870_();
+ needsRemoval = true;
+ }
+ if (!server.m_6998_() && (entity instanceof net.minecraft.world.entity.animal.Animal || entity instanceof net.minecraft.world.entity.animal.WaterAnimal)) {
+ entity.m_146870_();
+ needsRemoval = true;
+ }
+ return !needsRemoval;
+ }
+ return !needsRemoval;
+ }));
+ // CraftBukkit end
}
Expand Down Expand Up @@ -160,12 +170,17 @@
}

}
@@ -946,7 +_,7 @@
@@ -946,7 +_,12 @@

private CompletableFuture<Optional<CompoundTag>> m_214963_(ChunkPos p_214964_) {
return this.m_223454_(p_214964_).thenApplyAsync((p_214907_) -> {
- return p_214907_.map(this::m_214947_);
+ return p_214907_.map((nbttagcompound) -> m_214947_(nbttagcompound));
+ return p_214907_.map(new Function<CompoundTag, CompoundTag>() {
+ @Override
+ public CompoundTag apply(CompoundTag compoundTag) {
+ return m_214947_(compoundTag);
+ }
+ });
}, Util.m_183991_());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,50 @@
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
@@ -38,42 +_,7 @@
import net.minecraft.network.chat.OutgoingChatMessage;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
-import net.minecraft.network.protocol.game.ClientGamePacketListener;
-import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
-import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
-import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
-import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
-import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket;
-import net.minecraft.network.protocol.game.ClientboundContainerClosePacket;
-import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket;
-import net.minecraft.network.protocol.game.ClientboundContainerSetDataPacket;
-import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
-import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
-import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
-import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
-import net.minecraft.network.protocol.game.ClientboundHorseScreenOpenPacket;
-import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
-import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
-import net.minecraft.network.protocol.game.ClientboundMerchantOffersPacket;
-import net.minecraft.network.protocol.game.ClientboundOpenBookPacket;
-import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
-import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
-import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
-import net.minecraft.network.protocol.game.ClientboundPlayerCombatEndPacket;
-import net.minecraft.network.protocol.game.ClientboundPlayerCombatEnterPacket;
-import net.minecraft.network.protocol.game.ClientboundPlayerCombatKillPacket;
-import net.minecraft.network.protocol.game.ClientboundPlayerLookAtPacket;
-import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket;
-import net.minecraft.network.protocol.game.ClientboundResourcePackPacket;
-import net.minecraft.network.protocol.game.ClientboundRespawnPacket;
-import net.minecraft.network.protocol.game.ClientboundServerDataPacket;
-import net.minecraft.network.protocol.game.ClientboundSetCameraPacket;
-import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket;
-import net.minecraft.network.protocol.game.ClientboundSetHealthPacket;
-import net.minecraft.network.protocol.game.ClientboundSoundPacket;
-import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
-import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
-import net.minecraft.network.protocol.game.ServerboundClientInformationPacket;
+import net.minecraft.network.protocol.game.*;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
@@ -95,6 +_,7 @@
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -324,7 +368,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.m_127521_(throwable, "Ticking player");
CrashReportCategory crashreportcategory = crashreport.m_127514_("Player being ticked");
@@ -563,16 +_,52 @@
@@ -563,16 +_,53 @@
}

private void m_9104_(ObjectiveCriteria p_9105_, int p_9106_) {
Expand Down Expand Up @@ -366,6 +410,7 @@
+
+ // SPIGOT-943 - only call if they have an inventory open
+ if (this.f_36096_ != this.f_36095_) {
+ useHandleContainerClose = true;
+ this.m_6915_();
+ }
+
Expand Down Expand Up @@ -425,7 +470,7 @@
}
}

@@ -701,26 +_,53 @@
@@ -701,26 +_,58 @@
}

private boolean m_9216_() {
Expand Down Expand Up @@ -459,7 +504,11 @@
+ }
+
@Nullable
- public Entity m_5489_(ServerLevel p_9180_) {
public Entity m_5489_(ServerLevel p_9180_) {
+ return changeDimension(p_9180_, p_9180_.m_8871_());
+ }
+
+ @Nullable
+ public Entity changeDimension(ServerLevel p_9180_, net.minecraftforge.common.util.ITeleporter teleporter) {
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_9180_.m_46472_())) return null;
+ if (this.m_5803_()) return this; // CraftBukkit - SPIGOT-3154
Expand Down Expand Up @@ -613,15 +662,16 @@
ResourceKey<Level> resourcekey = p_9210_.m_46472_();
ResourceKey<Level> resourcekey1 = this.m_9236_().m_46472_();
CriteriaTriggers.f_10588_.m_19757_(this, resourcekey, resourcekey1);
@@ -830,18 +_,23 @@
@@ -829,19 +_,25 @@
this.f_36096_.m_38946_();
}

+ public Either<Player.BedSleepingProblem, Unit> bedResult; // Mohist
public Either<Player.BedSleepingProblem, Unit> m_7720_(BlockPos p_9115_) {
+ boolean force = startSleepInBed_force.getAndSet(false);
+ bedResult = null;
+ java.util.Optional<BlockPos> optAt = java.util.Optional.of(p_9115_);
+ Player.BedSleepingProblem ret = net.minecraftforge.event.ForgeEventFactory.onPlayerSleepInBed(this, optAt);
+ Either<Player.BedSleepingProblem, Unit> bedResult = null;
+ if (ret != null) return Either.left(ret);
+ if (ret != null) bedResult = Either.left(ret);
Direction direction = this.m_9236_().m_8055_(p_9115_).m_61143_(HorizontalDirectionalBlock.f_54117_);
if (!this.m_5803_() && this.m_6084_()) {
- if (!this.m_9236_().m_6042_().f_63858_()) {
Expand All @@ -635,10 +685,10 @@
- return Either.left(Player.BedSleepingProblem.OBSTRUCTED);
+ bedResult = Either.left(Player.BedSleepingProblem.OBSTRUCTED);
} else {
- this.m_9158_(this.m_9236_().m_46472_(), p_9115_, this.m_146908_(), false, true);
+ this.cause = PlayerSpawnChangeEvent.Cause.BED; // Mohist
this.m_9158_(this.m_9236_().m_46472_(), p_9115_, this.m_146908_(), false, true);
- if (this.m_9236_().m_46461_()) {
- return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW);
+ this.setRespawnPosition(this.m_9236_().m_46472_(), p_9115_, this.m_146908_(), false, true, PlayerSpawnChangeEvent.Cause.BED); // CraftBukkit
+ if (!net.minecraftforge.event.ForgeEventFactory.fireSleepingTimeCheck(this, optAt)) {
+ bedResult = Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW);
} else {
Expand Down Expand Up @@ -677,7 +727,7 @@
+ return bedResult; // return immediately if the result is not bypassable by plugins
+ }
+
+ if (force) {
+ if (startSleepInBed_force.getAndSet(false)) {
+ bedResult = Either.right(Unit.INSTANCE);
+ }
+
Expand Down Expand Up @@ -741,7 +791,7 @@
}

}
@@ -939,16 +_,53 @@
@@ -939,16 +_,60 @@
this.f_8940_ = this.f_8940_ % 100 + 1;
}

Expand Down Expand Up @@ -780,6 +830,13 @@
+ // Mohist end
+
+ boolean cancelled = false;
+ // Mohist start - Moved from CraftEventFactory#callInventoryOpenEvent(...) to fix mixin issues
+ if (this.f_36096_ != this.f_36095_) {
+ useHandleContainerClose = true;
+ this.m_6915_();
+ CraftEventFactory.alreadyProcessed = true;
+ }
+ // Mohist end
+ abstractcontainermenu = CraftEventFactory.callInventoryOpenEvent(this, abstractcontainermenu, cancelled);
+ if (abstractcontainermenu == null && !cancelled) { // Let pre-cancelled events fall through
+ // SPIGOT-5263 - close chest if cancelled
Expand Down Expand Up @@ -842,7 +899,24 @@
}

public void m_6986_(ItemStack p_9082_, InteractionHand p_9083_) {
@@ -1002,6 +_,7 @@
@@ -994,14 +_,23 @@
this.f_8906_.m_9829_(ClientboundBlockEntityDataPacket.m_195642_(p_9099_, BlockEntity::m_187482_));
}

+ public boolean useHandleContainerClose = false; // Mohist
public void m_6915_() {
+ if (useHandleContainerClose) {
+ this.f_8906_.m_7951_(new ServerboundContainerClosePacket(this.f_36096_.f_38840_));
+ useHandleContainerClose = false;
+ } else {
+ CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
+ this.f_8906_.m_9829_(new ClientboundContainerClosePacket(this.f_36096_.f_38840_));
+ this.m_9230_();
+ }
this.f_8906_.m_9829_(new ClientboundContainerClosePacket(this.f_36096_.f_38840_));
- this.m_9230_();
}

public void m_9230_() {
this.f_36096_.m_6877_(this);
this.f_36095_.m_150414_(this.f_36096_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@
this.f_19804_.m_135381_(f_20961_, Mth.m_14036_(p_21154_, 0.0F, this.m_21233_()));
}

@@ -1036,35 +_,26 @@
@@ -1036,35 +_,28 @@
}

public boolean m_6469_(DamageSource p_21016_, float p_21017_) {
Expand All @@ -565,6 +565,8 @@
return false;
- } else if (this.m_21224_()) {
+ } else if (this.m_213877_() || this.f_20890_ || this.m_21223_() <= 0.0F) { // CraftBukkit - Don't allow entities that got set to dead/killed elsewhere to get damaged and die
+ return false;
+ } else if (this.m_21224_()) { // Mohist
return false;
} else if (p_21016_.m_269533_(DamageTypeTags.f_268745_) && this.m_21023_(MobEffects.f_19607_)) {
return false;
Expand Down Expand Up @@ -937,7 +939,7 @@
}

if (p_21194_ <= 0.0F) {
@@ -1583,26 +_,183 @@
@@ -1583,26 +_,219 @@

protected void m_6475_(DamageSource p_21240_, float p_21241_) {
if (!this.m_6673_(p_21240_)) {
Expand Down Expand Up @@ -969,11 +971,14 @@
+ }
+ final float originalDamage = p_21241_;
+
+ Function<Double, Double> hardHat = f -> {
+ if (p_21240_.m_269533_(DamageTypeTags.f_268627_) && !LivingEntity.this.m_6844_(EquipmentSlot.HEAD).m_41619_()) {
+ return -(f - (f * 0.75F));
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ if (p_21240_.m_269533_(DamageTypeTags.f_268627_) && !LivingEntity.this.m_6844_(EquipmentSlot.HEAD).m_41619_()) {
+ return -(input - (input * 0.75F));
+ }
+ return -0.0;
+ }
+ return -0.0;
+ };
+ float hardHatModifier = hardHat.apply((double) p_21241_).floatValue();
+ p_21241_ += hardHatModifier;
Expand All @@ -985,40 +990,73 @@
+ if (!shieldEvent.isCanceled()) {
+ var blocked = shieldEvent.getBlockedDamage();
+ shieldTakesDamage = shieldEvent.shieldTakesDamage();
+ blocking = f13 -> -(double) blocked;
+ blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return -(double) blocked;
+ }
+ };
+ } else {
+ blocking = f13 -> 0d;
+ blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return 0d;
+ }
+ };
+ }
+ } else {
+ blocking = f13 -> 0d;
+ blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return 0d;
+ }
+ };
+ }
+ float blockingModifier = blocking.apply((double) p_21241_).floatValue();
+ p_21241_ += blockingModifier;
+
+ Function<Double, Double> armor = f -> -(f - LivingEntity.this.m_21161_(p_21240_, f.floatValue()));
+ Function<Double, Double> armor = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return -(input - LivingEntity.this.m_21161_(p_21240_, input.floatValue()));
+ }
+ };
+ float armorModifier = armor.apply((double) p_21241_).floatValue();
+ p_21241_ += armorModifier;
+
+ Function<Double, Double> resistance = f -> {
+ if (!p_21240_.m_269533_(DamageTypeTags.f_268437_) && LivingEntity.this.m_21023_(MobEffects.f_19606_) && !p_21240_.m_269533_(DamageTypeTags.f_268630_)) {
+ int i = (LivingEntity.this.m_21124_(MobEffects.f_19606_).m_19564_() + 1) * 5;
+ int j = 25 - i;
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ Function<Double, Double> resistance = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ if (!p_21240_.m_269533_(DamageTypeTags.f_268437_) && LivingEntity.this.m_21023_(MobEffects.f_19606_) && !p_21240_.m_269533_(DamageTypeTags.f_268630_)) {
+ int i = (LivingEntity.this.m_21124_(MobEffects.f_19606_).m_19564_() + 1) * 5;
+ int j = 25 - i;
+ float f1 = input.floatValue() * (float) j;
+ return -(input - (f1 / 25.0F));
+ }
+ return -0.0;
+ }
+ return -0.0;
+ };
+ float resistanceModifier = resistance.apply((double) p_21241_).floatValue();
+ p_21241_ += resistanceModifier;
+
+ // Mohist start
+ float mohist = this.m_6515_(p_21240_, p_21241_);
+ float magicModifier = -(p_21241_ - mohist);
+ Function<Double, Double> magic = f -> (double) magicModifier;
+ Function<Double, Double> magic = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return (double) magicModifier;
+ }
+ };
+ p_21241_ += magicModifier;
+ // Mohist end
+
+ Function<Double, Double> absorption = f -> -(Math.max(f - Math.max(f - LivingEntity.this.m_6103_(), 0.0F), 0.0F));
+ Function<Double, Double> absorption = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double input) {
+ return -(Math.max(input - Math.max(input - LivingEntity.this.m_6103_(), 0.0F), 0.0F));
+ }
+ };
+ float absorptionModifier = absorption.apply((double) p_21241_).floatValue();
+
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, p_21240_, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
Expand Down
Loading