-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Blukzen/feature/13-disabled-items
feature/13: Lab disabled items configuration
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/blukzen/createlab/mixin/ServerPlayerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
package com.blukzen.createlab.mixin; | ||
|
||
import com.blukzen.createlab.CreateLabConfig; | ||
import com.blukzen.createlab.dimension.LabDimensions; | ||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.BlockPos; | ||
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.CallbackInfo; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Mixin(ServerPlayerEntity.class) | ||
public abstract class ServerPlayerEntityMixin extends PlayerEntity { | ||
Predicate<ItemStack> DISABLED_ITEMS = (ItemStack itemStack) -> CreateLabConfig.disabledItems.get().contains(itemStack.getItem().getRegistryName().toString()); | ||
|
||
public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) { | ||
super(world, pos, yaw, profile); | ||
} | ||
|
||
@Inject(method = "tick", at = @At("HEAD")) | ||
public void tick(CallbackInfo ci) { | ||
if (this.level.dimension().equals(LabDimensions.LABDIM)) { | ||
if (DISABLED_ITEMS.test(getMainHandItem())) { | ||
getMainHandItem().setCount(0); | ||
} | ||
} | ||
} | ||
} |