Skip to content

Commit

Permalink
Merge pull request #701 from CrazyDev05/dev/1.21.1
Browse files Browse the repository at this point in the history
Several Automata Turtle fixes
  • Loading branch information
SirEndii authored Jan 20, 2025
2 parents 3328b5b + 2ed1cfe commit d19de49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Optional;

import static de.srendi.advancedperipherals.common.setup.DataComponents.FUEL_CONSUMPTION_RATE;

Expand All @@ -30,7 +31,8 @@ public FuelAbility(@NotNull T owner) {
*/
protected int getConsumptionRate() {
DataComponentPatch settings = owner.getDataStorage();
int rate = settings.get(FUEL_CONSUMPTION_RATE.get()).get();
Optional<? extends Integer> opt = settings.get(FUEL_CONSUMPTION_RATE.get());
int rate = opt != null && opt.isPresent() ? opt.get() : 0;
if (rate == 0) {
setConsumptionRate(DEFAULT_FUEL_CONSUMING_RATE);
return DEFAULT_FUEL_CONSUMING_RATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ protected Pair<MethodResult, CompoundTag> getPointData() {
return Pair.onlyRight(settings.get(POINT_DATA_MARK.get()));
}

protected void setPointData(@NotNull CompoundTag data) {
TurtlePeripheralOwner owner = automataCore.getPeripheralOwner();
PatchedDataComponentMap settings = PatchedDataComponentMap.fromPatch(DataComponentMap.EMPTY, owner.getDataStorage());
settings.set(POINT_DATA_MARK.get(), data);
owner.putDataStorage(settings.asPatch());
}

private int getWarpCost(SingleOperationContext context) {
FuelAbility<?> fuelAbility = automataCore.getPeripheralOwner().getAbility(PeripheralOwnerAbility.FUEL);
Objects.requireNonNull(fuelAbility);
Expand All @@ -72,6 +79,7 @@ public final MethodResult savePoint(String name) {
return MethodResult.of(null, "Cannot add new point, limit reached");

data.put(name, NBTUtil.toNBT(automataCore.getPeripheralOwner().getPos()));
setPointData(data);
return MethodResult.of(true);
}

Expand All @@ -87,6 +95,7 @@ public final MethodResult deletePoint(String name) {
return MethodResult.of(null, "Cannot find point to delete");

data.remove(name);
setPointData(data);
return MethodResult.of(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ public HitResult findHit(boolean skipEntity, boolean skipBlock, @Nullable Predic
if (level().isEmptyBlock(blockPos) || blockPos.equals(blockPosition())) {
return null;
}
BlockHitResult shaped = traceContext.getBlockShape(level().getBlockState(blockPos), level(), blockPos)
.clip(rayTraceContext.getFrom(), rayTraceContext.getTo(), blockPos);
if (shaped != null && shaped.getType() != HitResult.Type.MISS) {
return shaped;
}
return new BlockHitResult(new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()), traceDirection, blockPos, false);
}, rayTraceContext -> BlockHitResult.miss(rayTraceContext.getTo(), traceDirection, new BlockPos((int) rayTraceContext.getTo().x, (int) rayTraceContext.getTo().y, (int) rayTraceContext.getTo().z)));
}
Expand Down

0 comments on commit d19de49

Please sign in to comment.