Skip to content

Commit 2870eaf

Browse files
committed
feauture/13: Implemented removing disabled items
1 parent 5b1dedf commit 2870eaf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
package com.blukzen.createlab.mixin;
22

3+
import com.blukzen.createlab.CreateLabConfig;
4+
import com.blukzen.createlab.dimension.LabDimensions;
35
import com.mojang.authlib.GameProfile;
46
import net.minecraft.entity.player.PlayerEntity;
57
import net.minecraft.entity.player.ServerPlayerEntity;
8+
import net.minecraft.item.ItemStack;
69
import net.minecraft.util.math.BlockPos;
710
import net.minecraft.world.World;
811
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;
917

1018
@Mixin(ServerPlayerEntity.class)
1119
public abstract class ServerPlayerEntityMixin extends PlayerEntity {
20+
Predicate<ItemStack> DISABLED_ITEMS = (ItemStack itemStack) -> CreateLabConfig.disabledItems.get().contains(itemStack.getItem().getRegistryName().toString());
21+
1222
public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) {
1323
super(world, pos, yaw, profile);
1424
}
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+
}
1534
}

0 commit comments

Comments
 (0)