Skip to content

Commit

Permalink
0.8.2: check curios inv
Browse files Browse the repository at this point in the history
  • Loading branch information
3TUSK committed Sep 15, 2024
1 parent 287dbd4 commit 9d91f8d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Area Control
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=BSD-3-Clause
# The mod version. See https://semver.org/
mod_version=0.8.1
mod_version=0.8.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.MarkerFactory;
import org.teacon.areacontrol.api.Area;
import org.teacon.areacontrol.api.AreaProperties;
import org.teacon.areacontrol.compat.curios.CuriosCapability;
import org.teacon.areacontrol.impl.AreaChecks;
import org.teacon.areacontrol.impl.AreaMath;
import org.teacon.areacontrol.network.ACNetworking;
Expand Down Expand Up @@ -107,6 +108,10 @@ public static void onPlayerTick(PlayerTickEvent.Pre event) {
AreaChecks.checkInv(mainInv.items, currentArea, player);
AreaChecks.checkInv(mainInv.armor, currentArea, player);
AreaChecks.checkInv(mainInv.offhand, currentArea, player);
var extraInv = player.getCapability(CuriosCapability.CURIO_INV);
if (extraInv != null) {
AreaChecks.checkInv(extraInv, currentArea, player);
}
// Seize vehicles if disallowed
var riding = player.getVehicle();
if (riding != null && !AreaChecks.checkPropFor(currentArea, player, AreaProperties.ALLOW_RIDE, BuiltInRegistries.ENTITY_TYPE.getKey(riding.getType()), AreaControlConfig.allowRideEntity)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.teacon.areacontrol.compat.curios;

import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.capabilities.EntityCapability;
import net.neoforged.neoforge.items.IItemHandler;

public final class CuriosCapability {
public static final EntityCapability<IItemHandler, Void> CURIO_INV = EntityCapability.createVoid(ResourceLocation.fromNamespaceAndPath("curios", "item_handler"), IItemHandler.class);
}
20 changes: 19 additions & 1 deletion src/main/java/org/teacon/areacontrol/impl/AreaChecks.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.teacon.areacontrol.impl;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.locale.Language;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.server.permission.PermissionAPI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -90,6 +91,23 @@ public static void checkInv(List<ItemStack> inv, @Nullable Area currentArea, Pla
}
}

public static void checkInv(IItemHandler inv, Area currentArea, Player player) {
// If bypass mode is on, then this check can be skipped.
if (AreaControlPlayerTracker.INSTANCE.hasBypassModeOnForArea(player, currentArea)) {
return;
}
ConfiscationInv seizedInv = player.getData(AreaControlBorderControl.CONFISCATION_INV);
var invSize = inv.getSlots();
for (int i = 0; i < invSize; i++) {
var item = inv.getStackInSlot(i);
if (!item.isEmpty() && !checkPossess(currentArea, item.getItem())) {
ItemStack seized = inv.extractItem(i, Integer.MAX_VALUE, false);
seizedInv.add(seized);
player.displayClientMessage(Component.translatable("area_control.notice.possess_disabled_item", item.getHoverName()), true);
}
}
}

// This is a separate method because area.allow_possess currently has a different logic
public static boolean checkPossess(Area area, Item item) {
var targetId = BuiltInRegistries.ITEM.getKey(item);
Expand Down

0 comments on commit 9d91f8d

Please sign in to comment.