Skip to content

Commit

Permalink
Config Option to prevent fake players from using the Time wand - Reso…
Browse files Browse the repository at this point in the history
…lves #235
  • Loading branch information
Direwolf20-MC committed Oct 19, 2024
1 parent f201408 commit 9e13278
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.common.util.FakePlayer;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem;
Expand All @@ -48,6 +49,8 @@ public TimeWand() {
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
if (!Config.TIME_WAND_FAKE_PLAYER_ALLOWED.get() && player instanceof FakePlayer)
return InteractionResultHolder.fail(itemStack);
BlockHitResult blockhitresult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.SOURCE_ONLY);
if (blockhitresult.getType() == HitResult.Type.BLOCK) {
if (pickupFluid(level, player, itemStack, blockhitresult))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

Expand Down Expand Up @@ -485,7 +486,7 @@ default boolean useOnAbility(UseOnContext pContext) {
}

default boolean bindDrops(UseOnContext pContext) {
if (pContext.getLevel().isClientSide) return false;
if (pContext.getLevel().isClientSide) return true;
Player player = pContext.getPlayer();
if (player == null) return false;
if (!player.isShiftKeyDown()) return false;
Expand All @@ -498,9 +499,17 @@ default boolean bindDrops(UseOnContext pContext) {
if (blockEntity == null) return false;
IItemHandler handler = pLevel.getCapability(Capabilities.ItemHandler.BLOCK, pPos, pContext.getClickedFace());
if (handler == null) return false;
setBoundInventory(pStack, new NBTHelpers.BoundInventory(GlobalPos.of(pLevel.dimension(), pPos), pContext.getClickedFace()));
pContext.getPlayer().displayClientMessage(Component.translatable("justdirethings.boundto", Component.translatable(pLevel.dimension().location().getPath()), "[" + pPos.toShortString() + "]"), true);
player.playNotifySound(SoundEvents.END_PORTAL_FRAME_FILL, SoundSource.PLAYERS, 1.0F, 1.0F);
NBTHelpers.BoundInventory boundInventory = ToggleableTool.getBoundInventory(pStack);
NBTHelpers.BoundInventory newBind = new NBTHelpers.BoundInventory(GlobalPos.of(pLevel.dimension(), pPos), pContext.getClickedFace());
if (boundInventory != null && boundInventory.equals(newBind)) {
removeBoundInventory(pStack);
pContext.getPlayer().displayClientMessage(Component.translatable("justdirethings.bindremoved"), true);
player.playNotifySound(SoundEvents.ENDER_EYE_DEATH, SoundSource.PLAYERS, 1.0F, 1.0F);
} else {
setBoundInventory(pStack, newBind);
pContext.getPlayer().displayClientMessage(Component.translatable("justdirethings.boundto", Component.translatable(pLevel.dimension().location().getPath()), "[" + pPos.toShortString() + "]"), true);
player.playNotifySound(SoundEvents.END_PORTAL_FRAME_FILL, SoundSource.PLAYERS, 1.0F, 1.0F);
}
return true;
}

Expand Down Expand Up @@ -578,6 +587,11 @@ static void setBoundInventory(ItemStack stack, NBTHelpers.BoundInventory boundIn
stack.set(JustDireDataComponents.BOUND_INVENTORY, boundInventory);
}

static void removeBoundInventory(ItemStack stack) {
stack.remove(JustDireDataComponents.BOUND_INVENTORY);
}

@Nullable
static NBTHelpers.BoundInventory getBoundInventory(ItemStack stack) {
return stack.getOrDefault(JustDireDataComponents.BOUND_INVENTORY, null);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/direwolf20/justdirethings/setup/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class Config {
public static ModConfigSpec.IntValue TIMEWAND_RF_COST;
public static ModConfigSpec.DoubleValue TIMEWAND_FLUID_COST;
public static ModConfigSpec.ConfigValue<Integer> TIME_WAND_MAX_MULTIPLIER;
public static ModConfigSpec.BooleanValue TIME_WAND_FAKE_PLAYER_ALLOWED;

public static final String CATEGORY_PARADOX_MACHINE = "paradox_machine";
public static ModConfigSpec.IntValue PARADOX_TOTAL_FLUID_CAPACITY;
Expand Down Expand Up @@ -258,6 +259,8 @@ private static void timeWandConfig() {
}
return validPowerOfTwo;
});
TIME_WAND_FAKE_PLAYER_ALLOWED = COMMON_BUILDER.comment("Can fake players use the Time Wand (Like in the clickers)?")
.define("time_wand_fake_player_allowed", true);
COMMON_BUILDER.pop();
}

Expand Down

0 comments on commit 9e13278

Please sign in to comment.