diff --git a/CHANGELOG.md b/CHANGELOG.md index bcca9a6e0..dde6f4283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.19.2-0.7.37r] - 2024-10-06 + +### Added +- Wandering Trader config + +### Changed +- Safe the owner of the memory card to the inventory manager after a player places the card into the manager and clear the card after. Resolves a security issue where players could eventually steal memory cards from other players + +### Fixed +- [#660] Fixed that the inventory manager's `getItemInHand` function adds a blank nbt tag to the item +- [#636] Fixed that the automata's `useOnBlock` function will return PASS in some specific case +- [#645] Fixed that the inventory functions for the powah integration would always return nil +- Fixed that some entity operations don't have enough range + ## [1.19.2-0.7.36r] - 2024-06-11 ### Added diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index be6a19c9b..446418865 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -932,7 +932,7 @@ public static List listCells(IGridNode node) { if (!iterator.hasNext()) return items; while (iterator.hasNext()) { IStorageProvider entity = iterator.next().getService(IStorageProvider.class); - if (entity == null || !(entity instanceof DriveBlockEntity drive)) + if (!(entity instanceof DriveBlockEntity drive)) continue; InternalInventory inventory = drive.getInternalInventory(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java index 027869f62..318d49a4b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java @@ -56,7 +56,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) selectedTool.setDamageValue(previousDamageValue); - return MethodResult.of(true, result.toString()); + return MethodResult.of(result.consumesAction(), result.toString()); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java index 79368507e..6f4035522 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java @@ -24,7 +24,7 @@ public final MethodResult feedSoul() { InteractionResult result = owner.withPlayer(APFakePlayer::useOnEntity); automataCore.addRotationCycle(3); - return MethodResult.of(true, result.toString()); + return MethodResult.of(result.consumesAction(), result.toString()); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java index 02de8ae91..f45f045df 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java @@ -52,11 +52,16 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn @Override public void setItem(int index, @NotNull ItemStack stack) { - if (stack.getItem() instanceof MemoryCardItem && stack.hasTag() && stack.getTag().contains("ownerId")) { - UUID owner = stack.getTag().getUUID("ownerId"); - this.owner = owner; - stack.getTag().remove("ownerId"); - stack.getTag().remove("owner"); + if (stack.getItem() instanceof MemoryCardItem) { + if (stack.hasTag() && stack.getTag().contains("ownerId")) { + UUID owner = stack.getTag().getUUID("ownerId"); + this.owner = owner; + stack.getTag().remove("ownerId"); + stack.getTag().remove("owner"); + } else if (stack != this.getItem(index)) { + // Only clear owner when the new card item is not the current item + this.owner = null; + } } else { this.owner = null; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java index d6954e640..a947a4c53 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java @@ -44,7 +44,6 @@ import java.lang.ref.WeakReference; import java.util.List; -import java.util.Optional; import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; @@ -92,7 +91,6 @@ public boolean canAttack(@NotNull LivingEntity livingEntity) { public void openTextEdit(@NotNull SignBlockEntity sign) { } - @Override public boolean isSilent() { return true; @@ -318,46 +316,59 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic if (skipEntity) return blockHit; - List entities = level.getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1, 1, 1), collidablePredicate); + List entities = level.getEntities(this, getBoundingBox().expandTowards(look.x * range, look.y * range, look.z * range).inflate(1), collidablePredicate); LivingEntity closestEntity = null; Vec3 closestVec = null; - double closestDistance = range; + double closestDistance = blockHit.getType() == HitResult.Type.MISS ? range * range : distanceToSqr(blockHit.getLocation()); for (Entity entityHit : entities) { - if (!(entityHit instanceof LivingEntity) || entityFilter != null && !entityFilter.test(entityHit)) + if (!(entityHit instanceof LivingEntity entity)) { + continue; + } + // TODO: maybe let entityFilter returns the priority of the entity, instead of only returns the closest one. + if (entityFilter != null && !entityFilter.test(entity)) { + continue; + } + + // Removed a lot logic here to make Automata cores interact like a player. + // However, the results for some edge cases may change. Need more review and tests. + + // Hit vehicle before passenger + if (entity.isPassenger()) { continue; - // Add litter bigger that just pick radius - AABB box = entityHit.getBoundingBox().inflate(entityHit.getPickRadius() + 0.5); - Optional clipResult = box.clip(origin, target); + } + AABB box = entity.getBoundingBox(); + Vec3 clipVec; if (box.contains(origin)) { - if (closestDistance >= 0.0D) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipResult.orElse(origin); - closestDistance = 0.0D; + clipVec = origin; + } else { + clipVec = box.clip(origin, target).orElse(null); + if (clipVec == null) { + continue; } - } else if (clipResult.isPresent()) { - Vec3 clipVec = clipResult.get(); - double distance = origin.distanceTo(clipVec); - - if (distance < closestDistance || closestDistance == 0.0D) { - if (entityHit == entityHit.getRootVehicle() && !entityHit.canRiderInteract()) { - if (closestDistance == 0.0D) { - closestEntity = (LivingEntity) entityHit; - closestVec = clipVec; - } - } else { - closestEntity = (LivingEntity) entityHit; - closestVec = clipVec; - closestDistance = distance; - } + } + double distance = origin.distanceToSqr(clipVec); + // Ignore small enough distance + if (distance <= 1e-6) { + distance = 0; + } + if (distance > closestDistance) { + continue; + } + if (distance == closestDistance && closestEntity != null) { + // Hit larger entity before smaller + if (closestEntity.getBoundingBox().getSize() >= box.getSize()) { + continue; } } + closestEntity = entity; + closestVec = clipVec; + closestDistance = distance; } - if (closestEntity != null && closestDistance <= range && (blockHit.getType() == HitResult.Type.MISS || distanceToSqr(blockHit.getLocation()) > closestDistance * closestDistance)) { + if (closestEntity != null) { return new EntityHitResult(closestEntity, closestVec); - } else { - return blockHit; } + return blockHit; } }