Skip to content

Commit

Permalink
feat: 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Oct 23, 2024
1 parent 6b24003 commit 6a88250
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 138 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx5G
org.gradle.parallel=true
# Mod Properties
mod_version=0.4.6
mod_version=0.4.7-alpha+1.21.2
archices_preview_version=

maven_group=com.github.zly2006
Expand All @@ -11,9 +11,9 @@ archives_base_name=enclosure-fabric
rei_version = 9.1.550

# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.7

# Fabric API
fabric_version=0.106.0+1.21.1
fabric_version=0.106.1+1.21.2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -36,7 +37,7 @@ private void onRender(DrawContext context, int index, int y, int x, int entryWid
);
}
}
context.drawTexture(NOTIFY_TEXTURE, x + 24, y + 24, 0, offset, 8, 8, 8, 16);
context.drawTexture(RenderLayer::getGuiTexturedOverlay, NOTIFY_TEXTURE, x + 24, y + 24, 0, offset, 8, 8, 8, 16);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -45,7 +46,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
int height = 150;
int x = (parent.width - 200) / 2;
int y = (parent.height - height) / 2;
context.drawTexture(TEXTURE, x, y, 0, 0, 200, 150, 200, 150);
context.drawTexture(RenderLayer::getGuiTexturedOverlay, TEXTURE, x, y, 0, 0, 200, 150, 200, 150);
context.drawTextWrapped(textRenderer, message, x + 10, y + 10, 180, 0xFFFFFF);
yesButton.setY(y + height - 30);
noButton.setY(y + height - 30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
public class MixinAbstractSignBlock {
@Inject(method = "openEditScreen", at = @At("HEAD"), cancellable = true)
private void openEditScreen(PlayerEntity player, SignBlockEntity blockEntity, boolean front, CallbackInfo ci) {
if (player instanceof ServerPlayerEntity) {
if (player instanceof ServerPlayerEntity serverPlayer) {
@SuppressWarnings("DataFlowIssue")
EnclosureArea area = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) blockEntity.getWorld(), blockEntity.getPos());
if (area != null && !area.hasPerm((ServerPlayerEntity) player, Permission.EDIT_SIGN)) {
player.sendMessage(Permission.EDIT_SIGN.getNoPermissionMsg(player));
if (area != null && !area.hasPerm(serverPlayer, Permission.EDIT_SIGN)) {
serverPlayer.sendMessage(Permission.EDIT_SIGN.getNoPermissionMsg(player));
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void onEating(PlayerEntity player, Hand hand, CallbackInfoReturnable<Act
}
EnclosureArea area = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) this.getWorld(), getBlockPos());
if (area != null && !area.hasPerm((ServerPlayerEntity) player, FEED_ANIMAL)) {
player.sendMessage(FEED_ANIMAL.getNoPermissionMsg(player));
player.sendMessage(FEED_ANIMAL.getNoPermissionMsg(player), false);
cir.setReturnValue(ActionResult.FAIL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.AbstractBoatEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
Expand All @@ -15,7 +15,7 @@

import static com.github.zly2006.enclosure.utils.Permission.VEHICLE;

@Mixin(BoatEntity.class)
@Mixin(AbstractBoatEntity.class)
public abstract class MixinBoatEntity extends Entity {
protected MixinBoatEntity(EntityType<?> entityType, World world) {
super(entityType, world);
Expand All @@ -24,7 +24,7 @@ protected MixinBoatEntity(EntityType<?> entityType, World world) {
@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void onInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (!ServerMain.INSTANCE.checkPermission(getWorld(), getBlockPos(), player, VEHICLE)) {
player.sendMessage(VEHICLE.getNoPermissionMsg(player));
player.sendMessage(VEHICLE.getNoPermissionMsg(player), true);
cir.setReturnValue(ActionResult.FAIL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import net.minecraft.item.BucketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -27,14 +27,14 @@ public class MixinBucketItem {
@Shadow @Final private Fluid fluid;

@Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;canPlayerModifyAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;)Z"), locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true)
private void onUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir, ItemStack itemStack, BlockHitResult blockHitResult, BlockPos blockPos, Direction direction, BlockPos blockPos2) {
private void onUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<ActionResult> cir, ItemStack itemStack, BlockHitResult blockHitResult, BlockPos blockPos, Direction direction, BlockPos blockPos2) {
if (user instanceof ServerPlayerEntity player) {
Permission permission = this.fluid == Fluids.EMPTY ? Permission.BREAK_BLOCK : Permission.PLACE_BLOCK;
if (!ServerMain.INSTANCE.checkPermission(world, blockPos, player, permission) ||
!ServerMain.INSTANCE.checkPermission(world, blockPos2, player, permission)) {
player.currentScreenHandler.syncState();
player.sendMessage(permission.getNoPermissionMsg(player));
cir.setReturnValue(TypedActionResult.fail(itemStack));
cir.setReturnValue(ActionResult.FAIL);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.github.zly2006.enclosure.ServerMain;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.ChestBoatEntity;
import net.minecraft.entity.vehicle.AbstractBoatEntity;
import net.minecraft.entity.vehicle.AbstractChestBoatEntity;
import net.minecraft.item.Item;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand All @@ -14,13 +15,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Supplier;

import static com.github.zly2006.enclosure.utils.Permission.CONTAINER;
import static com.github.zly2006.enclosure.utils.Permission.VEHICLE;

@Mixin(ChestBoatEntity.class)
public class MixinChestBoatEntity extends BoatEntity {
public MixinChestBoatEntity(EntityType<? extends BoatEntity> entityType, World world) {
super(entityType, world);
@Mixin(AbstractChestBoatEntity.class)
public abstract class MixinChestBoatEntity extends AbstractBoatEntity {
public MixinChestBoatEntity(EntityType<? extends AbstractBoatEntity> type, World world, Supplier<Item> itemSupplier) {
super(type, world, itemSupplier);
}

@Inject(method = "canPlayerUse", at = @At("HEAD"), cancellable = true)
Expand All @@ -39,10 +42,10 @@ private void canPlayerUse(PlayerEntity player, CallbackInfoReturnable<Boolean> c
@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void onInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (!ServerMain.INSTANCE.checkPermission(getWorld(), getBlockPos(), player, VEHICLE)) {
player.sendMessage(VEHICLE.getNoPermissionMsg(player));
player.sendMessage(VEHICLE.getNoPermissionMsg(player), true);
cir.setReturnValue(ActionResult.FAIL);
} else if (!ServerMain.INSTANCE.checkPermission(getWorld(), getBlockPos(), player, CONTAINER)) {
player.sendMessage(CONTAINER.getNoPermissionMsg(player));
player.sendMessage(CONTAINER.getNoPermissionMsg(player), true);
cir.setReturnValue(ActionResult.FAIL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -35,7 +34,7 @@ public class MixinChiseledBookshelfBlock {
)
private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir, @Local OptionalInt optionalInt) {
if (optionalInt.isPresent() && !ServerMain.INSTANCE.checkPermission(world, pos, player, Permission.CONTAINER)) {
player.sendMessage(CONTAINER.getNoPermissionMsg(player));
player.sendMessage(CONTAINER.getNoPermissionMsg(player), true);
cir.setReturnValue(ActionResult.FAIL);
}
}
Expand All @@ -48,10 +47,10 @@ private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity pla
),
cancellable = true
)
private void onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ItemActionResult> cir, @Local OptionalInt optionalInt) {
private void onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir, @Local OptionalInt optionalInt) {
if (optionalInt.isPresent() && !ServerMain.INSTANCE.checkPermission(world, pos, player, Permission.CONTAINER)) {
player.sendMessage(CONTAINER.getNoPermissionMsg(player));
cir.setReturnValue(ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION);
player.sendMessage(CONTAINER.getNoPermissionMsg(player), true);
cir.setReturnValue(ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ protected MixinCreeperEntity(EntityType<? extends HostileEntity> entityType, Wor

@Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/CreeperEntity;ignite()V"), cancellable = true)
private void onUse(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
EnclosureArea area = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) getWorld(), getBlockPos());
if (area != null && !area.hasPerm((ServerPlayerEntity) player, Permission.PRIME_TNT)) {
player.sendMessage(Permission.PRIME_TNT.getNoPermissionMsg(player));
cir.setReturnValue(ActionResult.FAIL);
if (player instanceof ServerPlayerEntity serverPlayer) {
EnclosureArea area = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) serverPlayer.getWorld(), getBlockPos());
if (area != null && !area.hasPerm(serverPlayer, Permission.PRIME_TNT)) {
serverPlayer.sendMessage(Permission.PRIME_TNT.getNoPermissionMsg(serverPlayer));
cir.setReturnValue(ActionResult.FAIL);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import net.minecraft.item.CrossbowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -19,12 +19,12 @@
@Mixin(CrossbowItem.class)
public class MixinCrossBowItem {
@Inject(method = "use", at = @At(value = "INVOKE",target = "Lnet/minecraft/item/CrossbowItem;shootAll(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/item/ItemStack;FFLnet/minecraft/entity/LivingEntity;)V"), cancellable = true)
private void onShoot(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir, @Local ItemStack itemStack) {
private void onShoot(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<ActionResult> cir, @Local ItemStack itemStack) {
if (user instanceof ServerPlayerEntity player) {
if (!ServerMain.INSTANCE.checkPermission(player, SHOOT, player.getBlockPos())) {
player.sendMessage(SHOOT.getNoPermissionMsg(player));
player.currentScreenHandler.syncState(); // update player's inventory
cir.setReturnValue(TypedActionResult.fail(itemStack));
cir.setReturnValue(ActionResult.FAIL);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,48 @@
import com.github.zly2006.enclosure.EnclosureArea;
import com.github.zly2006.enclosure.ServerMain;
import com.github.zly2006.enclosure.utils.Permission;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(Explosion.class)
@Mixin(ExplosionBehavior.class)
public abstract class MixinExplosion {
@Shadow
@Final
private ObjectArrayList<BlockPos> affectedBlocks;

@Shadow
@Final
private World world;
@Inject(
method = "canDestroyBlock",
at = @At("HEAD"),
cancellable = true
)
private void canDestroyBlock(Explosion explosion, BlockView world, BlockPos pos, BlockState state, float power, CallbackInfoReturnable<Boolean> cir) {
if (world instanceof ServerWorld serverWorld) {
EnclosureArea a = ServerMain.INSTANCE.getSmallestEnclosure(serverWorld, pos);
if (a != null && !a.hasPubPerm(Permission.EXPLOSION)) {
cir.setReturnValue(false);
}
}
}

@ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;<init>(DDD)V", ordinal = 1), method = "collectBlocksAndDamageEntities")
private List<Entity> protectEntities(List<Entity> list) {
if (!world.isClient) {
list.removeIf(entity -> {
assert entity != null;
BlockPos pos = entity.getBlockPos();
EnclosureArea a = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) world, pos);
return a != null && !a.hasPubPerm(Permission.EXPLOSION);
});
this.affectedBlocks.removeIf(pos -> {
EnclosureArea a = ServerMain.INSTANCE.getSmallestEnclosure((ServerWorld) world, pos);
return a != null && !a.hasPubPerm(Permission.EXPLOSION);
});
@Inject(
method = "shouldDamage",
at = @At("HEAD"),
cancellable = true
)
private void shouldDamage(Explosion explosion, Entity entity, CallbackInfoReturnable<Boolean> cir) {
if (entity.getWorld() instanceof ServerWorld serverWorld) {
EnclosureArea a = ServerMain.INSTANCE.getSmallestEnclosure(serverWorld, entity.getBlockPos());
if (a != null && !a.hasPubPerm(Permission.EXPLOSION)) {
cir.setReturnValue(false);
}
}
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.FarmlandBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,9 +17,9 @@
public class MixinFarmlandBlock {
@Inject(method = "setToDirt", at = @At("HEAD"), cancellable = true)
private static void onLandedUpon(Entity entity, BlockState state, World world, BlockPos pos, CallbackInfo ci) {
if (entity instanceof PlayerEntity player) {
if (entity instanceof ServerPlayerEntity player) {
if (!ServerMain.INSTANCE.checkPermission(world, pos, player, Permission.FARMLAND_DESTROY)) {
entity.sendMessage(Permission.FARMLAND_DESTROY.getNoPermissionMsg(player));
player.sendMessage(Permission.FARMLAND_DESTROY.getNoPermissionMsg(player));
ci.cancel();
}
}
Expand Down
Loading

0 comments on commit 6a88250

Please sign in to comment.