Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 11, 2024
1 parent e3ccbf1 commit fc9d39e
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 344 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.izzel.arclight.common.mixin.core.network.protocol;

import io.izzel.arclight.common.bridge.core.network.common.ServerCommonPacketListenerBridge;
import io.izzel.arclight.common.bridge.core.server.MinecraftServerBridge;
import net.minecraft.CrashReport;
import net.minecraft.ReportedException;
import net.minecraft.network.PacketListener;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketUtils;
import net.minecraft.server.RunningOnDifferentThreadException;
import net.minecraft.util.thread.BlockableEventLoop;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftServer;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -30,7 +27,7 @@ public class PacketThreadUtilMixin {
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packetIn, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
if (!executor.isSameThread()) {
executor.executeIfPossible(() -> {
if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerCommonPacketListenerBridge && ((ServerCommonPacketListenerBridge) processor).bridge$processedDisconnect())) {
if (processor instanceof ServerCommonPacketListenerBridge && ((ServerCommonPacketListenerBridge) processor).bridge$processedDisconnect()) {
return;
}
if (processor.isAcceptingMessages()) {
Expand Down Expand Up @@ -60,8 +57,6 @@ public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T

});
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
} else if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerCommonPacketListenerBridge && ((ServerCommonPacketListenerBridge) processor).bridge$processedDisconnect())) {
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,59 @@ public void sendChanges() {
player.bridge$getBukkitEntity().injectScaledMaxHealth(set, false);
}
}

/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void sendPairingData(ServerPlayer player, final Consumer<Packet<?>> consumer) {
if (this.entity.isRemoved()) {
return;
}
Packet<?> packet = this.entity.getAddEntityPacket();
this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0f / 360.0f);
consumer.accept(packet);
if (this.trackedDataValues != null) {
consumer.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), this.trackedDataValues));
}
boolean flag = this.trackDelta;
if (this.entity instanceof LivingEntity livingEntity) {
Collection<AttributeInstance> collection = livingEntity.getAttributes().getSyncableAttributes();
if (this.entity.getId() == player.getId()) {
((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
}
if (!collection.isEmpty()) {
consumer.accept(new ClientboundUpdateAttributesPacket(this.entity.getId(), collection));
}
if (livingEntity.isFallFlying()) {
flag = true;
}
}
this.ap = this.entity.getDeltaMovement();
if (flag && !(this.entity instanceof LivingEntity)) {
consumer.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap));
}
if (this.entity instanceof LivingEntity) {
ArrayList<Pair<EquipmentSlot, ItemStack>> list = Lists.newArrayList();
for (EquipmentSlot enumitemslot : EquipmentSlot.values()) {
ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot);
if (itemstack.isEmpty()) continue;
list.add(Pair.of(enumitemslot, itemstack.copy()));
}
if (!list.isEmpty()) {
consumer.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list));
}
((LivingEntity) this.entity).detectEquipmentUpdates();
}
if (!this.entity.getPassengers().isEmpty()) {
consumer.accept(new ClientboundSetPassengersPacket(this.entity));
}
if (this.entity.isPassenger()) {
consumer.accept(new ClientboundSetPassengersPacket(this.entity.getVehicle()));
}
if (this.entity instanceof Mob mob && mob.isLeashed()) {
consumer.accept(new ClientboundSetEntityLinkPacket(mob, mob.getLeashHolder()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
import net.minecraft.world.entity.ai.behavior.TryLaySpawnOnWaterNearLand;
import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluids;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(TryLaySpawnOnWaterNearLand.class)
public class TryLaySpawnOnWaterNearLandMixin {

/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static BehaviorControl<LivingEntity> create(Block block) {
return BehaviorBuilder.create((instance) -> {
return instance.group(instance.absent(MemoryModuleType.ATTACK_TARGET), instance.present(MemoryModuleType.WALK_TARGET), instance.present(MemoryModuleType.IS_PREGNANT)).apply(instance, (memoryAccessor, memoryAccessor2, memoryAccessor3) -> {
return (serverLevel, livingEntity, l) -> {
if (!livingEntity.isInWater() && livingEntity.onGround()) {
BlockPos blockPos = livingEntity.blockPosition().below();

for (Direction direction : Direction.Plane.HORIZONTAL) {
BlockPos blockPos2 = blockPos.relative(direction);
if (serverLevel.getBlockState(blockPos2).getCollisionShape(serverLevel, blockPos2).getFaceShape(Direction.UP).isEmpty() && serverLevel.getFluidState(blockPos2).is(Fluids.WATER)) {
BlockPos blockPos3 = blockPos2.above();
if (serverLevel.getBlockState(blockPos3).isAir()) {
BlockState blockState = block.defaultBlockState();
if (!CraftEventFactory.callEntityChangeBlockEvent(livingEntity, blockPos3, blockState)) {
memoryAccessor3.erase();
return true;
}
serverLevel.setBlock(blockPos3, blockState, 3);
serverLevel.gameEvent(GameEvent.BLOCK_PLACE, blockPos3, GameEvent.Context.of(livingEntity, blockState));
serverLevel.playSound(null, livingEntity, SoundEvents.FROG_LAY_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
memoryAccessor3.erase();
return true;
}
}
}

return true;
} else {
return false;
}
};
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TridentItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.player.PlayerRiptideEvent;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

Expand Down Expand Up @@ -46,10 +44,10 @@ public class TridentItemMixin {
return true;
}

@Inject(method = "releaseUsing", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/player/Player;getYRot()F"))
public void arclight$riptide(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft, CallbackInfo ci) {
@Redirect(method = "releaseUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;push(DDD)V"))
private void arclight$riptide(Player instance, double x, double y, double z, ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (!DistValidate.isValid(worldIn)) return;
PlayerRiptideEvent event = new PlayerRiptideEvent(((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror(stack));
Bukkit.getPluginManager().callEvent(event);
CraftEventFactory.callPlayerRiptideEvent(instance, stack, (float) x, (float) y, (float) z);
instance.push(x, y, z);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"world.entity.ai.behavior.ResetProfessionMixin",
"world.entity.ai.behavior.StartAttackingMixin",
"world.entity.ai.behavior.StopAttackingIfTargetInvalidMixin",
"world.entity.ai.behavior.TryLaySpawnOnWaterNearLandMixin",
"world.entity.ai.behavior.VillagerMakeLoveMixin",
"world.entity.ai.behavior.warden.DiggingMixin",
"world.entity.ai.brain.BrainUtilMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"server.Main_ServerShutdownThreadMixin_Vanilla",
"server.dedicated.DedicatedServer_ServerInputThreadMixin_Vanilla",
"server.dedicated.DedicatedServerMixin_Vanilla",
"server.level.ServerEntityMixin_Vanilla",
"server.level.ServerPlayerGameMode_Vanilla",
"world.entity.EntityMixin_Vanilla",
"world.entity.LivingEntityMixin_Vanilla",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"bukkit.CraftServerMixin_Fabric",
"core.network.ServerCommonPacketListenerImplMixin_Fabric",
"core.network.ServerLoginNetHandlerMixin_Fabric",
"core.server.level.ServerEntityMixin_Fabric",
"core.world.entity.EntityMixin_Fabric",
"core.world.entity.LivingEntityMixin_Fabric",
"core.world.entity.monster.ZombieMixin_Fabric",
Expand Down
Loading

0 comments on commit fc9d39e

Please sign in to comment.