Skip to content

Commit

Permalink
fix: fish
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Jun 5, 2024
1 parent 5fe75de commit 81f2e8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
package com.github.zly2006.enclosure.mixin;

import com.github.zly2006.enclosure.ServerMain;
import com.github.zly2006.enclosure.utils.Permission;
import net.minecraft.entity.Bucketable;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
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.callback.CallbackInfoReturnable;

@Mixin(MobEntity.class)
public abstract class MixinMobEntity extends LivingEntity {
protected MixinMobEntity(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}

@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (getWorld() instanceof ServerWorld world) {
if (this instanceof Bucketable && player.getStackInHand(hand).isOf(Items.WATER_BUCKET)) {
if (!ServerMain.INSTANCE.checkPermission(getWorld(), getBlockPos(), player, Permission.FISH)) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;


// createSpawnPacket(world.getChunkManager().chunkLoadingManager.entityTrackers);
// fixme
// serverPlayer.networkHandler.sendPacket(createSpawnPacket());
serverPlayer.sendMessage(Permission.FISH.getNoPermissionMsg(player));
serverPlayer.currentScreenHandler.syncState();
cir.setReturnValue(ActionResult.FAIL);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@

import com.github.zly2006.enclosure.ServerMain;
import com.github.zly2006.enclosure.utils.Permission;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.TadpoleEntity;
import net.minecraft.entity.Bucketable;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
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.callback.CallbackInfoReturnable;

@Mixin(TadpoleEntity.class)
public abstract class MixinTadpoleEntity extends Entity {
public MixinTadpoleEntity(EntityType<?> type, World world) {
super(type, world);
}
import java.util.Optional;

@Inject(method = "interactMob", at = @At("HEAD"), cancellable = true)
private void interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (ServerMain.INSTANCE.checkPermission(getWorld(), getBlockPos(), player, Permission.FISH)) {
return;
@Mixin(Bucketable.class)
public interface MixinTadpoleEntity {
@Inject(method = "tryBucket", at = @At("HEAD"), cancellable = true)
private static <T extends LivingEntity & Bucketable> void interactMob(PlayerEntity player, Hand hand, T entity, CallbackInfoReturnable<Optional<ActionResult>> cir) {
if (player instanceof ServerPlayerEntity serverPlayer) {
if (!ServerMain.INSTANCE.checkPermission(player.getWorld(), entity.getBlockPos(), player, Permission.FISH)) {
player.sendMessage(Permission.FISH.getNoPermissionMsg(player));
serverPlayer.networkHandler.sendPacket(entity.createSpawnPacket(serverPlayer.getServerWorld().getChunkManager().chunkLoadingManager.entityTrackers.get(entity.getId()).entry));
serverPlayer.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(entity.getId(), entity.getDataTracker().getChangedEntries()));
cir.setReturnValue(Optional.empty());
}
}
player.sendMessage(Permission.FISH.getNoPermissionMsg(player));
cir.setReturnValue(ActionResult.FAIL);
}
}
1 change: 1 addition & 0 deletions src/main/resources/enclosure.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ accessible field net/minecraft/util/UserCache$Entry profile Lcom/mojang/authlib/
accessible field net/minecraft/util/UserCache byName Ljava/util/Map;
extendable class net/minecraft/datafixer/DataFixTypes
accessible field net/minecraft/server/world/ServerChunkLoadingManager entityTrackers Lit/unimi/dsi/fastutil/ints/Int2ObjectMap;
accessible field net/minecraft/server/world/ServerChunkLoadingManager$EntityTracker entry Lnet/minecraft/server/network/EntityTrackerEntry;

0 comments on commit 81f2e8d

Please sign in to comment.