From c28a618d0b9845b1174a9d23e07def74fd2f49ad Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 15 Jan 2025 12:48:30 -0700 Subject: [PATCH 1/7] add mobToLua --- .../advancedperipherals/common/util/LuaConverter.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index 2429d3b36..d1e40be74 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -76,11 +76,15 @@ public static Map livingEntityToLua(LivingEntity entity, boolean return data; } - public static Map animalToLua(Animal animal, ItemStack itemInHand, boolean detailed) { + public static Map mobToLua(Mob animal, boolean detailed) { Map data = livingEntityToLua(animal, detailed); - data.put("baby", animal.isBaby()); - data.put("inLove", animal.isInLove()); data.put("aggressive", animal.isAggressive()); + return data; + } + + public static Map animalToLua(Animal animal, ItemStack itemInHand, boolean detailed) { + Map data = mobToLua(animal, detailed); + data.put("inLove", animal.isInLove()); if (animal instanceof IForgeShearable shareable && !itemInHand.isEmpty()) { data.put("shareable", shareable.isShearable(itemInHand, animal.level, animal.blockPosition())); } @@ -121,6 +125,7 @@ public static Map completeEntityToLua(Entity entity, ItemStack i public static Map completeEntityToLua(Entity entity, ItemStack itemInHand, boolean detailed) { if (entity instanceof Player player) return playerToLua(player, detailed); if (entity instanceof Animal animal) return animalToLua(animal, itemInHand, detailed); + if (entity instanceof Mob mob) return mobToLua(mob, detailed); if (entity instanceof LivingEntity livingEntity) return livingEntityToLua(livingEntity, detailed); return entityToLua(entity, detailed); } From e140d5f8aeb46102607ad0fc165672da2908333d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 13:36:46 -0700 Subject: [PATCH 2/7] update automata turtle logic fix fake player will not look at correct position after moved to another block fix fake player is not able to see non-collise blocks abstract getConnectedPeripheral(Class) in IPeripheralOwner add updateBlock method for update sign text (close IntelligenceModding/Advanced-Peripherals-Features#91) --- .../owner/BlockEntityPeripheralOwner.java | 9 ++- .../computercraft/owner/IPeripheralOwner.java | 10 +++- .../owner/PocketPeripheralOwner.java | 20 ++++++- .../owner/TurtlePeripheralOwner.java | 21 ++++++- .../OverpoweredEndAutomataCorePeripheral.java | 10 +--- ...oweredHusbandryAutomataCorePeripheral.java | 9 +-- ...OverpoweredWeakAutomataCorePeripheral.java | 9 +-- .../WeakAutomataCorePeripheral.java | 5 ++ .../plugins/AutomataBlockHandPlugin.java | 59 +++++++++++++++---- .../plugins/AutomataEntityHandPlugin.java | 4 +- .../blockentities/DistanceDetectorEntity.java | 5 +- .../modules/ModulePeripheralOwner.java | 21 ++++++- .../common/util/HitResultUtil.java | 54 ++++++++--------- .../common/util/LuaConverter.java | 1 + .../common/util/fakeplayer/APFakePlayer.java | 17 ++++-- .../fakeplayer/FakePlayerProviderTurtle.java | 5 +- .../peripherals/AutomataCorePeripheral.java | 26 +++++++- src/main/resources/META-INF/mods.toml | 2 +- 18 files changed, 201 insertions(+), 86 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java index a909d1eda..81250b6f2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/BlockEntityPeripheralOwner.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.owner; +import dan200.computercraft.api.peripheral.IPeripheral; import de.srendi.advancedperipherals.common.blocks.base.BaseBlock; import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity; import de.srendi.advancedperipherals.common.util.DataStorageUtil; @@ -20,7 +21,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Objects; -import java.util.function.Function; public class BlockEntityPeripheralOwner extends BasePeripheralOwner { @@ -90,7 +90,7 @@ public void markDataStorageDirty() { } @Override - public T1 withPlayer(Function function) { + public T1 withPlayer(APFakePlayer.Action function) { throw new NotImplementedException(); } @@ -124,4 +124,9 @@ public BlockEntityPeripheralOwner attachFuel() { attachAbility(PeripheralOwnerAbility.FUEL, new TileEntityFuelAbility<>(this)); return this; } + + @Override + public U getConnectedPeripheral(Class type) { + throw new NotImplementedException(); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java index 287c94e4e..aa27af5cd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.owner; +import dan200.computercraft.api.peripheral.IPeripheral; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation; import net.minecraft.core.BlockPos; @@ -14,7 +15,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.function.Function; public interface IPeripheralOwner { @@ -39,7 +39,7 @@ default Vec3 getCenterPos() { void markDataStorageDirty(); - T withPlayer(Function function); + T withPlayer(APFakePlayer.Action function); ItemStack getToolInMainHand(); @@ -70,4 +70,10 @@ default void attachOperation(Collection> operations) { for (IPeripheralOperation operation : operations) operationAbility.registerOperation(operation); } + + T getConnectedPeripheral(Class type); + + default boolean hasConnectedPeripheral(Class type) { + return getConnectedPeripheral(type) == null; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java index 7c3f431ec..ffafe5d54 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java @@ -1,9 +1,11 @@ package de.srendi.advancedperipherals.common.addons.computercraft.owner; +import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.pocket.IPocketAccess; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.DataStorageUtil; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; +import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; @@ -17,8 +19,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Function; - public class PocketPeripheralOwner extends BasePeripheralOwner { private final IPocketAccess pocket; @@ -97,7 +97,7 @@ public void markDataStorageDirty() { } @Override - public T withPlayer(Function function) { + public T withPlayer(APFakePlayer.Action function) { throw new NotImplementedException(); } @@ -125,4 +125,18 @@ public boolean isMovementPossible(@NotNull Level level, @NotNull BlockPos pos) { public boolean move(@NotNull Level level, @NotNull BlockPos pos) { return false; } + + @Override + public T getConnectedPeripheral(Class type) { + IPeripheral foundPeripheral = pocket.getUpgrades().values().stream() + .filter(peripheral -> { + if (peripheral == null || type.isInstance(peripheral)) { + return false; + } + return peripheral instanceof IBasePeripheral basePeripheral ? basePeripheral.isEnabled() : true; + }) + .findFirst() + .orElse(null); + return (T) foundPeripheral; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java index aee1a67c7..17dd0e3fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/TurtlePeripheralOwner.java @@ -2,6 +2,7 @@ import com.mojang.authlib.GameProfile; import dan200.computercraft.ComputerCraft; +import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.TurtlePermissions; @@ -9,6 +10,7 @@ import de.srendi.advancedperipherals.common.util.DataStorageUtil; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; import de.srendi.advancedperipherals.common.util.fakeplayer.FakePlayerProviderTurtle; +import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; @@ -20,7 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Function; +import java.util.stream.Stream; public class TurtlePeripheralOwner extends BasePeripheralOwner { public final ITurtleAccess turtle; @@ -82,7 +84,7 @@ public void markDataStorageDirty() { } @Override - public T withPlayer(Function function) { + public T withPlayer(APFakePlayer.Action function) { return FakePlayerProviderTurtle.withPlayer(turtle, function); } @@ -132,4 +134,19 @@ public TurtlePeripheralOwner attachFuel(int maxFuelConsumptionLevel) { attachAbility(PeripheralOwnerAbility.FUEL, new TurtleFuelAbility(this, maxFuelConsumptionLevel)); return this; } + + @Override + public T getConnectedPeripheral(Class type) { + IPeripheral foundPeripheral = Stream.of(TurtleSide.values()) + .map(side -> turtle.getPeripheral(side)) + .filter(peripheral -> { + if (peripheral == null || type.isInstance(peripheral)) { + return false; + } + return peripheral instanceof IBasePeripheral basePeripheral ? basePeripheral.isEnabled() : true; + }) + .findFirst() + .orElse(null); + return (T) foundPeripheral; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java index 392dcfaf2..ad2fd2f70 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java @@ -2,9 +2,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; -import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; -import de.srendi.advancedperipherals.common.configuration.APConfig; public class OverpoweredEndAutomataCorePeripheral extends EndAutomataCorePeripheral { @@ -12,12 +10,10 @@ public class OverpoweredEndAutomataCorePeripheral extends EndAutomataCorePeriphe public OverpoweredEndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); - setAttribute(ATTR_STORING_TOOL_DURABILITY); } - public void addRotationCycle(int count) { - super.addRotationCycle(count); - if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) - owner.destroyUpgrade(); + @Override + public boolean canOverpowerAction() { + return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java index 220e9ce49..fe4eaf449 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java @@ -2,9 +2,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; -import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; -import de.srendi.advancedperipherals.common.configuration.APConfig; public class OverpoweredHusbandryAutomataCorePeripheral extends HusbandryAutomataCorePeripheral { @@ -12,13 +10,10 @@ public class OverpoweredHusbandryAutomataCorePeripheral extends HusbandryAutomat public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2); - setAttribute(ATTR_STORING_TOOL_DURABILITY); } @Override - public void addRotationCycle(int count) { - super.addRotationCycle(count); - if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) - owner.destroyUpgrade(); + public boolean canOverpowerAction() { + return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java index 1b19eb40e..7f8e406ae 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java @@ -2,9 +2,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; -import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier; -import de.srendi.advancedperipherals.common.configuration.APConfig; public class OverpoweredWeakAutomataCorePeripheral extends WeakAutomataCorePeripheral { @@ -12,13 +10,10 @@ public class OverpoweredWeakAutomataCorePeripheral extends WeakAutomataCorePerip public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) { super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER1); - setAttribute(ATTR_STORING_TOOL_DURABILITY); } @Override - public void addRotationCycle(int count) { - super.addRotationCycle(count); - if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get()) - owner.destroyUpgrade(); + public boolean canOverpowerAction() { + return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java index ea46ec4fa..04351bd45 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/WeakAutomataCorePeripheral.java @@ -44,4 +44,9 @@ public static void addIntegrationPlugin(Function opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); + float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; + float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; + return automataCore.withOperation(USE_ON_BLOCK, context -> { + TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); + ItemStack selectedTool = owner.getToolInMainHand(); + int previousDamageValue = selectedTool.getDamageValue(); + InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, (player) -> this.updateBlock(player, opts))); + if (result.consumesAction() && automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { + selectedTool.setDamageValue(previousDamageValue); + } + return MethodResult.of(result.consumesAction(), result.toString()); + }); + } + + private InteractionResult updateBlock(APFakePlayer player, Map options) { + Level world = player.getLevel(); + HitResult hit = player.findHit(true, false); + if (!(hit instanceof BlockHitResult blockHit)) { + return InteractionResult.PASS; + } + BlockPos pos = blockHit.getBlockPos(); + BlockEntity block = world.getBlockEntity(pos); + if (block instanceof SignBlockEntity sign) { + String text; + try { + text = TableHelper.optStringField(options, "text", null); + } catch (LuaException e) { + // Why not allow empty catch block? TAT + text = null; + } + if (text != null) { + setSignText(world, sign, StringUtil.convertAndToSectionMark(text)); + return InteractionResult.CONSUME; + } + } + return InteractionResult.PASS; + } + /** * placeBlock method will let turtle place a block with more details when compass has equipped. * It should not able to place fluids / use any item, because compass do not recognize them. @@ -110,10 +150,9 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx * text: the text going to write on the sign. Default is null */ @LuaFunction(mainThread = true) - public MethodResult placeBlock(@NotNull Map options) throws LuaException { + public final MethodResult placeBlock(@NotNull Map options) throws LuaException { ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle(); - CompassPeripheral compassPeripheral = Stream.of(TurtleSide.values()).map(side -> turtle.getPeripheral(side) instanceof CompassPeripheral compass ? compass : null).filter(peripheral -> peripheral != null).findFirst().orElse(null); - if (compassPeripheral == null || !compassPeripheral.isEnabled()) { + if (!automataCore.getPeripheralOwner().hasConnectedPeripheral(CompassPeripheral.class)) { return MethodResult.of(false, "COMPASS_NOT_EQUIPPED"); } int x = TableHelper.optIntField(options, "x", 0); @@ -176,12 +215,12 @@ private String deployOn(ItemStack stack, BlockPos position, Direction anchor, Di if (!(item instanceof BlockItem)) { return "NOT_BLOCK"; } - BlockItem block = (BlockItem) item; - InteractionResult res = block.place(context); + BlockItem blockItem = (BlockItem) item; + InteractionResult res = blockItem.place(context); if (!res.consumesAction()) { return "CANNOT_PLACE"; } - if (block instanceof SignItem) { + if (blockItem instanceof SignItem) { BlockEntity blockEntity = world.getBlockEntity(position); if (blockEntity instanceof SignBlockEntity sign) { String text = StringUtil.convertAndToSectionMark(TableHelper.optStringField(options, "text", null)); 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 318d49a4b..78843999b 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 @@ -53,9 +53,9 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)))); - if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY)) + if (automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { selectedTool.setDamageValue(previousDamageValue); - + } return MethodResult.of(result.consumesAction(), result.toString()); }); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java index 8858f9126..e809409fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/DistanceDetectorEntity.java @@ -11,6 +11,7 @@ import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -227,8 +228,8 @@ private HitResult getHitResult(Vec3 to, Vec3 from) { Level level = this.getLevel(); return switch (this.detectionType) { case ENTITY -> HitResultUtil.getEntityHitResult(to, from, level); - case BLOCK -> HitResultUtil.getBlockHitResult(to, from, level, this.ignoreTransparent, this.getBlockPos()); - case BOTH -> HitResultUtil.getHitResult(to, from, level, this.ignoreTransparent, this.getBlockPos()); + case BLOCK -> HitResultUtil.getBlockHitResult(to, from, level, this.ignoreTransparent ? HitResultUtil.IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, this.getBlockPos()); + case BOTH -> HitResultUtil.getHitResult(to, from, level, this.ignoreTransparent ? HitResultUtil.IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, this.getBlockPos()); }; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java index 67bf2b6f0..62d22cdeb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheralOwner.java @@ -1,8 +1,11 @@ package de.srendi.advancedperipherals.common.smartglasses.modules; +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.core.computer.ComputerSide; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BasePeripheralOwner; import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesComputer; import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer; +import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.FrontAndTop; @@ -15,7 +18,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Function; +import java.util.stream.Stream; public class ModulePeripheralOwner extends BasePeripheralOwner { @@ -82,7 +85,7 @@ public void markDataStorageDirty() { } @Override - public T withPlayer(Function function) { + public T withPlayer(APFakePlayer.Action function) { throw new NotImplementedException(); } @@ -111,4 +114,18 @@ public boolean move(@NotNull Level level, @NotNull BlockPos pos) { return false; } + @Override + public T getConnectedPeripheral(Class type) { + IPeripheral foundPeripheral = Stream.of(ComputerSide.values()) + .map(side -> computer.getPeripheral(side)) + .filter(peripheral -> { + if (peripheral == null || type.isInstance(peripheral)) { + return false; + } + return peripheral instanceof IBasePeripheral basePeripheral ? basePeripheral.isEnabled() : true; + }) + .findFirst() + .orElse(null); + return (T) foundPeripheral; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java index 95ea8d085..05f7d0b67 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/HitResultUtil.java @@ -22,31 +22,31 @@ public class HitResultUtil { /** * This method is used to get the hit result of an entity from the start position of a block * - * @param to the target position/max position - * @param from the source position like a block - * @param level the level - * @param ignoreTransparent if transparent blocks should be ignored + * @param to the target position/max position + * @param from the source position like a block + * @param level the level + * @param shapeGetter the block collision shape getter * @return the hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @NotNull - public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent) { - return getHitResult(to, from, level, ignoreTransparent, null); + public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, ClipContext.ShapeGetter shapeGetter) { + return getHitResult(to, from, level, shapeGetter, null); } /** * This method is used to get the hit result of an entity from the start position of a block * - * @param to the target position/max position - * @param from the source position like a block - * @param level the level - * @param ignoreTransparent if transparent blocks should be ignored - * @param source the source Entity/BlockPos that will be ignored + * @param to the target position/max position + * @param from the source position like a block + * @param level the level + * @param shapeGetter the block collision shape getter + * @param source the source Entity/BlockPos that will be ignored * @return the hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @NotNull - public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreTransparent, Object source) { + public static HitResult getHitResult(Vec3 to, Vec3 from, Level level, ClipContext.ShapeGetter shapeGetter, Object source) { EntityHitResult entityResult = getEntityHitResult(to, from, level, source instanceof Entity ? (Entity) source : null); - BlockHitResult blockResult = getBlockHitResult(to, from, level, ignoreTransparent, source instanceof BlockPos ? (BlockPos) source : null); + BlockHitResult blockResult = getBlockHitResult(to, from, level, shapeGetter, source instanceof BlockPos ? (BlockPos) source : null); if (entityResult.getType() == HitResult.Type.MISS) { if (blockResult.getType() == HitResult.Type.MISS) { @@ -120,30 +120,30 @@ public static EntityHitResult getEntityHitResult(Vec3 to, Vec3 from, Level level /** * This method is used to get the hit result of a block from the start position of a block * - * @param to the target position/max position - * @param from the source position - * @param level the world - * @param ignoreNoOccluded if true, the method will ignore blocks which are not occluding like glass + * @param to the target position/max position + * @param from the source position + * @param level the world + * @param shapeGetter the block collision shape getter * @return the block hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @NotNull - public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded) { - return getBlockHitResult(to, from, level, ignoreNoOccluded, null); + public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, ClipContext.ShapeGetter shapeGetter) { + return getBlockHitResult(to, from, level, shapeGetter, null); } /** * This method is used to get the hit result of a block from the start position of a block * - * @param to the target position/max position - * @param from the source position - * @param level the world - * @param ignoreNoOccluded if true, the method will ignore blocks which are not occluding like glass - * @param source the source BlockPos that will be ignored + * @param to the target position/max position + * @param from the source position + * @param level the world + * @param shapeGetter the block collision shape getter + * @param source the source BlockPos that will be ignored * @return the block hit result. {@link BlockHitResult#miss(Vec3, Direction, BlockPos)} if nothing found */ @NotNull - public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, boolean ignoreNoOccluded, BlockPos source) { - return level.clip(new AdvancedClipContext(from, to, ignoreNoOccluded ? IgnoreNoOccludedContext.INSTANCE : ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null, source)); + public static BlockHitResult getBlockHitResult(Vec3 to, Vec3 from, Level level, ClipContext.ShapeGetter shapeGetter, BlockPos source) { + return level.clip(new AdvancedClipContext(from, to, shapeGetter, ClipContext.Fluid.NONE, null, source)); } public static class EmptyEntityHitResult extends EntityHitResult { @@ -166,7 +166,7 @@ public Type getType() { /** * A shape getter which ignores blocks which are not occluding like glass */ - private static class IgnoreNoOccludedContext implements ClipContext.ShapeGetter { + public static class IgnoreNoOccludedContext implements ClipContext.ShapeGetter { public static final IgnoreNoOccludedContext INSTANCE = new IgnoreNoOccludedContext(); private IgnoreNoOccludedContext() {} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index d1e40be74..db0949b70 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -13,6 +13,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; 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 3f3e66887..34cb0bddf 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 @@ -24,6 +24,7 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -43,7 +44,6 @@ import java.util.List; import java.util.UUID; -import java.util.function.Function; import java.util.function.Predicate; public class APFakePlayer extends FakePlayer { @@ -108,11 +108,11 @@ public float getEyeHeight(@NotNull Pose pose) { return 0; } - public static Function wrapActionWithRot(float yaw, float pitch, Function action) { + public static Action wrapActionWithRot(float yaw, float pitch, Action action) { return player -> player.doActionWithRot(yaw, pitch, action); } - public T doActionWithRot(float yaw, float pitch, Function action) { + public T doActionWithRot(float yaw, float pitch, Action action) { final float yRot = this.getYRot(), xRot = this.getXRot(); this.setRot(yRot + yaw, xRot + pitch); try { @@ -122,11 +122,11 @@ public T doActionWithRot(float yaw, float pitch, Function a } } - public static Function wrapActionWithShiftKey(boolean shift, Function action) { + public static Action wrapActionWithShiftKey(boolean shift, Action action) { return player -> player.doActionWithShiftKey(shift, action); } - public T doActionWithShiftKey(boolean shift, Function action) { + public T doActionWithShiftKey(boolean shift, Action action) { boolean old = this.isShiftKeyDown(); this.setShiftKeyDown(shift); try { @@ -290,7 +290,7 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic Direction traceDirection = Direction.getNearest(look.x, look.y, look.z); blockHit = BlockHitResult.miss(target, traceDirection, new BlockPos(target)); } else { - blockHit = HitResultUtil.getBlockHitResult(target, origin, level, false, this.source); + blockHit = HitResultUtil.getBlockHitResult(target, origin, level, ClipContext.Block.OUTLINE, this.source); } if (skipEntity) { @@ -349,4 +349,9 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic } return blockHit; } + + @FunctionalInterface + public interface Action { + T apply(APFakePlayer player); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java index 26fd8d024..159fcda5c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/FakePlayerProviderTurtle.java @@ -20,7 +20,6 @@ import org.valkyrienskies.core.api.ships.Ship; import java.util.WeakHashMap; -import java.util.function.Function; public final class FakePlayerProviderTurtle { @@ -55,8 +54,8 @@ public static void load(APFakePlayer player, ITurtleAccess turtle) { direction = new Vec3(newDir.x, newDir.y, newDir.z); } } + player.setPosRaw(position.x, position.y, position.z); player.lookAt(EntityAnchorArgument.Anchor.FEET, position.add(direction)); - player.moveTo(position.x, position.y, position.z, player.getYRot(), player.getXRot()); // Player inventory Inventory playerInventory = player.getInventory(); @@ -115,7 +114,7 @@ public static void unload(APFakePlayer player, ITurtleAccess turtle) { } } - public static T withPlayer(ITurtleAccess turtle, Function function) { + public static T withPlayer(ITurtleAccess turtle, APFakePlayer.Action function) { APFakePlayer player = getPlayer(turtle, turtle.getOwningPlayer()); load(player, turtle); T result = function.apply(player); diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java index 6327b87f6..cfd831709 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java @@ -4,6 +4,7 @@ import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; +import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation; import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperationContext; import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner; @@ -17,11 +18,9 @@ import java.util.Map; public abstract class AutomataCorePeripheral extends BasePeripheral { - - public static final String ATTR_STORING_TOOL_DURABILITY = "storingToolDurability"; - private final IAutomataCoreTier tier; private final Map attributes = new HashMap<>(); + protected boolean destroyed = false; protected AutomataCorePeripheral(String type, ITurtleAccess turtle, TurtleSide side, IAutomataCoreTier tier) { super(type, new TurtlePeripheralOwner(turtle, side)); @@ -84,4 +83,25 @@ public void setAttribute(String attribute) { public Direction validateSide(String direction) throws LuaException { return super.validateSide(direction); } + + public boolean isDestroyed() { + return this.destroyed; + } + + public boolean canOverpowerAction() { + return false; + } + + public abstract double getBreakChance(); + + public boolean afterOverpowerAction() { + if (isDestroyed() || !canOverpowerAction()) { + return false; + } + if (AdvancedPeripherals.RANDOM.nextDouble() <= getBreakChance()) { + this.destroyed = true; + owner.destroyUpgrade(); + } + return true; + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 33142efab..f4a652f24 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -29,7 +29,7 @@ side = "BOTH" modId = "computercraft" mandatory = true versionRange = "[${cc_version},)" -ordering = "NONE" +ordering = "AFTER" side = "BOTH" [[dependencies.${mod_id}]] modId = "curios" From d064e078de031339273cebadfead43e645fb60e4 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 16:10:03 -0700 Subject: [PATCH 3/7] != --- .../common/addons/computercraft/owner/IPeripheralOwner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java index aa27af5cd..2dd333a9d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/IPeripheralOwner.java @@ -74,6 +74,6 @@ default void attachOperation(Collection> operations) { T getConnectedPeripheral(Class type); default boolean hasConnectedPeripheral(Class type) { - return getConnectedPeripheral(type) == null; + return getConnectedPeripheral(type) != null; } } From 736ff91d06f3cbc55d46c6c799594d7330be01f7 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 16:18:16 -0700 Subject: [PATCH 4/7] add doc for updateBlock --- .../plugins/AutomataBlockHandPlugin.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 692e0a65d..4c3727bf2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -95,8 +95,21 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx }); } + /** + * updateBlock method let turtle update specific block's status. + * It require a compass to be equipped to perform actions. + * + * @param options A table contains where to find the block and how to update the block + * yaw: relative yaw + * pitch: relative pitch + * + * text: the text going to write if the target is a sign. + */ @LuaFunction(mainThread = true) public final MethodResult updateBlock(@NotNull IArguments arguments) throws LuaException { + if (!automataCore.getPeripheralOwner().hasConnectedPeripheral(CompassPeripheral.class)) { + return MethodResult.of(false, "COMPASS_NOT_EQUIPPED"); + } Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; @@ -138,7 +151,7 @@ private InteractionResult updateBlock(APFakePlayer player, Map options) { /** * placeBlock method will let turtle place a block with more details when compass has equipped. - * It should not able to place fluids / use any item, because compass do not recognize them. + * It should not able to place fluids / use any item, because compass does not recognize them. * * @param options A table contains how to place the block: * x: the x offset relative to the turtle. Default 0 From 39d331b41c68ca17797fd2be28743dbf82c35e22 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 16:23:06 -0700 Subject: [PATCH 5/7] remove A whitespace --- .../peripheral/plugins/AutomataBlockHandPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 4c3727bf2..35170f91a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -102,7 +102,7 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx * @param options A table contains where to find the block and how to update the block * yaw: relative yaw * pitch: relative pitch - * + * * text: the text going to write if the target is a sign. */ @LuaFunction(mainThread = true) From 8fc4714c958a13ba0155af0809740411a9126d30 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 16:42:15 -0700 Subject: [PATCH 6/7] add UPDATE_BLOCK operation --- .../addons/computercraft/operations/SingleOperation.java | 1 + .../peripheral/plugins/AutomataBlockHandPlugin.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java index f2075d2a4..980c329b9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SingleOperation.java @@ -10,6 +10,7 @@ public enum SingleOperation implements IPeripheralOperation { DIG(1000, 1), USE_ON_BLOCK(5000, 1), + UPDATE_BLOCK(500, 1), SUCK(1000, 1), USE_ON_ANIMAL(2500, 10), CAPTURE_ANIMAL(50_000, 100), diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index 35170f91a..6e6f23e2a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -41,9 +41,10 @@ import java.util.Collections; import java.util.Map; +import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.ACCURE_PLACE; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG; +import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.UPDATE_BLOCK; import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.USE_ON_BLOCK; -import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.ACCURE_PLACE; public class AutomataBlockHandPlugin extends AutomataCorePlugin { @@ -113,7 +114,7 @@ public final MethodResult updateBlock(@NotNull IArguments arguments) throws LuaE Map opts = arguments.count() > 0 ? arguments.getTable(0) : Collections.emptyMap(); float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0; float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0; - return automataCore.withOperation(USE_ON_BLOCK, context -> { + return automataCore.withOperation(UPDATE_BLOCK, context -> { TurtlePeripheralOwner owner = automataCore.getPeripheralOwner(); ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); From 4ce3f365178a2885945d18cb291102bf5dd2bffd Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 16 Jan 2025 17:18:57 -0700 Subject: [PATCH 7/7] canOverpowerAction -> canActiveOverpower --- .../metaphysics/OverpoweredEndAutomataCorePeripheral.java | 2 +- .../OverpoweredHusbandryAutomataCorePeripheral.java | 2 +- .../metaphysics/OverpoweredWeakAutomataCorePeripheral.java | 2 +- .../peripheral/plugins/AutomataBlockHandPlugin.java | 6 +++--- .../peripheral/plugins/AutomataEntityHandPlugin.java | 2 +- .../lib/peripherals/AutomataCorePeripheral.java | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java index ad2fd2f70..c925da8c1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredEndAutomataCorePeripheral.java @@ -13,7 +13,7 @@ public OverpoweredEndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide sid } @Override - public boolean canOverpowerAction() { + public boolean canActiveOverpower() { return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java index fe4eaf449..2fee520d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredHusbandryAutomataCorePeripheral.java @@ -13,7 +13,7 @@ public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSi } @Override - public boolean canOverpowerAction() { + public boolean canActiveOverpower() { return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java index 7f8e406ae..d8ed7a2c7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/metaphysics/OverpoweredWeakAutomataCorePeripheral.java @@ -13,7 +13,7 @@ public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide si } @Override - public boolean canOverpowerAction() { + public boolean canActiveOverpower() { return true; } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java index a823674c6..f7a89c5d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataBlockHandPlugin.java @@ -71,7 +71,7 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce if (!result.getLeft()) { return MethodResult.of(false, result.getRight()); } - if (automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { + if (automataCore.canActiveOverpower() && automataCore.afterOverpowerAction()) { selectedTool.setDamageValue(previousDamageValue); } return MethodResult.of(true, result.getRight()); @@ -89,7 +89,7 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, APFakePlayer::useOnBlock))); - if (result.consumesAction() && automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { + if (result.consumesAction() && automataCore.canActiveOverpower() && automataCore.afterOverpowerAction()) { selectedTool.setDamageValue(previousDamageValue); } return MethodResult.of(result.consumesAction(), result.toString()); @@ -119,7 +119,7 @@ public final MethodResult updateBlock(@NotNull IArguments arguments) throws LuaE ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, (player) -> this.updateBlock(player, opts))); - if (result.consumesAction() && automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { + if (result.consumesAction() && automataCore.canActiveOverpower() && automataCore.afterOverpowerAction()) { selectedTool.setDamageValue(previousDamageValue); } return MethodResult.of(result.consumesAction(), result.toString()); 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 4b40d26a2..b7ab0aba4 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 @@ -53,7 +53,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE ItemStack selectedTool = owner.getToolInMainHand(); int previousDamageValue = selectedTool.getDamageValue(); InteractionResult result = owner.withPlayer(APFakePlayer.wrapActionWithShiftKey(sneak, APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)))); - if (automataCore.canOverpowerAction() && automataCore.afterOverpowerAction()) { + if (automataCore.canActiveOverpower() && automataCore.afterOverpowerAction()) { selectedTool.setDamageValue(previousDamageValue); } return MethodResult.of(result.consumesAction(), result.toString()); diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java index c2c61c7aa..097e855d4 100644 --- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/AutomataCorePeripheral.java @@ -89,14 +89,14 @@ public boolean isDestroyed() { return this.destroyed; } - public boolean canOverpowerAction() { + public boolean canActiveOverpower() { return false; } public abstract double getBreakChance(); public boolean afterOverpowerAction() { - if (isDestroyed() || !canOverpowerAction()) { + if (isDestroyed() || !canActiveOverpower()) { return false; } if (AdvancedPeripherals.RANDOM.nextDouble() <= getBreakChance()) {