Skip to content

Commit

Permalink
fix java generic
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Apr 26, 2024
1 parent 6d7d52a commit f2506b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.core.apis.TableHelper;
import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner;
import de.srendi.advancedperipherals.common.util.LuaConverter;
import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral;
Expand Down Expand Up @@ -47,7 +48,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE
TurtlePeripheralOwner owner = automataCore.getPeripheralOwner();
ItemStack selectedTool = owner.getToolInMainHand();
int previousDamageValue = selectedTool.getDamageValue();
InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.useOnFilteredEntity(suitableEntity)));
InteractionResult result = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.useOnFilteredEntity(suitableEntity)));
if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY))
selectedTool.setDamageValue(previousDamageValue);

Expand All @@ -63,7 +64,7 @@ public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws Lu

automataCore.addRotationCycle();
TurtlePeripheralOwner owner = automataCore.getPeripheralOwner();
HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity)));
HitResult entityHit = owner.withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity)));
if (entityHit.getType() == HitResult.Type.MISS)
return MethodResult.of(null, "Nothing found");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.core.apis.TableHelper;
import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner;
import de.srendi.advancedperipherals.common.util.LuaConverter;
import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral;
Expand Down Expand Up @@ -74,7 +75,7 @@ public final MethodResult captureAnimal(@NotNull IArguments arguments) throws Lu
float yaw = opts != null ? (float) TableHelper.optNumberField(opts, "yaw", 0) : 0;
float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0;

HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, player -> player.findHit(false, true, suitableEntity)));
HitResult entityHit = automataCore.getPeripheralOwner().withPlayer(player -> player.doActionWithRot(yaw, pitch, p -> p.findHit(false, true, suitableEntity)));
if (entityHit.getType() == HitResult.Type.MISS)
return MethodResult.of(null, "Nothing found");
return automataCore.withOperation(CAPTURE_ANIMAL, context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.core.apis.TableHelper;
import de.srendi.advancedperipherals.common.addons.computercraft.owner.TurtlePeripheralOwner;
import de.srendi.advancedperipherals.common.util.LuaConverter;
import de.srendi.advancedperipherals.lib.peripherals.AutomataCorePeripheral;
Expand Down Expand Up @@ -50,7 +51,7 @@ public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws Lua
float pitch = opts != null ? (float) TableHelper.optNumberField(opts, "pitch", 0) : 0;

automataCore.addRotationCycle();
HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, apFakePlayer -> apFakePlayer.findHit(false, true)));
HitResult result = automataCore.getPeripheralOwner().withPlayer(apFakePlayer -> apFakePlayer.doActionWithRot(yaw, pitch, p -> p.findHit(false, true)));
if (result.getType() == HitResult.Type.MISS)
return MethodResult.of(null, "No entity find");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public float getEyeHeight(@NotNull Pose pose) {
return 0;
}

public T doActionWithRot<T>(float yaw, float pitch, Function<APFakePlayer, T> action) {
public <T> T doActionWithRot(float yaw, float pitch, Function<APFakePlayer, T> action) {
final float oldRot = this.getYRot();
this.setRot(oldRot + yaw, pitch);
try {
Expand Down

0 comments on commit f2506b0

Please sign in to comment.