|
1 | 1 | package com.blukzen.createlab.mixin;
|
2 | 2 |
|
| 3 | +import com.blukzen.createlab.CreateLabConfig; |
| 4 | +import com.blukzen.createlab.dimension.LabDimensions; |
3 | 5 | import com.mojang.authlib.GameProfile;
|
4 | 6 | import net.minecraft.entity.player.PlayerEntity;
|
5 | 7 | import net.minecraft.entity.player.ServerPlayerEntity;
|
| 8 | +import net.minecraft.item.ItemStack; |
6 | 9 | import net.minecraft.util.math.BlockPos;
|
7 | 10 | import net.minecraft.world.World;
|
8 | 11 | import org.spongepowered.asm.mixin.Mixin;
|
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 15 | + |
| 16 | +import java.util.function.Predicate; |
9 | 17 |
|
10 | 18 | @Mixin(ServerPlayerEntity.class)
|
11 | 19 | public abstract class ServerPlayerEntityMixin extends PlayerEntity {
|
| 20 | + Predicate<ItemStack> DISABLED_ITEMS = (ItemStack itemStack) -> CreateLabConfig.disabledItems.get().contains(itemStack.getItem().getRegistryName().toString()); |
| 21 | + |
12 | 22 | public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) {
|
13 | 23 | super(world, pos, yaw, profile);
|
14 | 24 | }
|
| 25 | + |
| 26 | + @Inject(method = "tick", at = @At("HEAD")) |
| 27 | + public void tick(CallbackInfo ci) { |
| 28 | + if (this.level.dimension().equals(LabDimensions.LABDIM)) { |
| 29 | + if (DISABLED_ITEMS.test(getMainHandItem())) { |
| 30 | + getMainHandItem().setCount(0); |
| 31 | + } |
| 32 | + } |
| 33 | + } |
15 | 34 | }
|
0 commit comments