Skip to content

Commit

Permalink
Gotta do something more important now
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 committed Jul 14, 2024
1 parent 20accb6 commit 3670e4a
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import java.util.Optional;

public record SlotFragment(int slot, Optional<BlockPos> maybePosition) implements Fragment {
public record SlotFragment(int slot, Optional<BlockPos> source) implements Fragment {
public static final MapCodec<SlotFragment> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.INT.fieldOf("slot").forGetter(SlotFragment::slot),
BlockPos.CODEC.optionalFieldOf("maybePosition").forGetter(SlotFragment::maybePosition)
BlockPos.CODEC.optionalFieldOf("source").forGetter(SlotFragment::source)
).apply(instance, SlotFragment::new));

@Override
Expand All @@ -30,8 +30,8 @@ public FragmentType<?> type() {

@Override
public Text asText() {
return Text.literal("slot %d at %s".formatted(slot, maybePosition.isPresent()
? "(%d, %d, %d)".formatted(maybePosition.get().getX(), maybePosition.get().getY(), maybePosition.get().getZ())
return Text.literal("slot %d at %s".formatted(slot, source.isPresent()
? "(%d, %d, %d)".formatted(source.get().getX(), source.get().getY(), source.get().getZ())
: "caster"));
}

Expand All @@ -40,27 +40,27 @@ public BooleanFragment asBoolean() {
return BooleanFragment.TRUE;
}

public ItemStack getStack(Trick source, SpellContext ctx) throws BlunderException {
public ItemStack getStack(Trick trickSource, SpellContext ctx) throws BlunderException {
Inventory inventory;
if (maybePosition.isPresent()) {
if (ctx.getWorld().getBlockEntity(maybePosition.get()) instanceof Inventory entity)
if (source.isPresent()) {
if (ctx.getWorld().getBlockEntity(source.get()) instanceof Inventory entity)
inventory = entity;
else throw new BlockInvalidBlunder(source);
else throw new BlockInvalidBlunder(trickSource);
} else {
if (ctx.getPlayer().isPresent())
inventory = ctx.getPlayer().get().getInventory();
else throw new NoPlayerBlunder(source);
else throw new NoPlayerBlunder(trickSource);
}


if (slot > inventory.size())
throw new NoSuchSlotBlunder(source);
throw new NoSuchSlotBlunder(trickSource);

return inventory.getStack(slot);
}

public void move(Trick source, SpellContext ctx) throws BlunderException {
if (maybePosition.isPresent())
ctx.useMana(source, (float)(32 + (ctx.getBlockPos().toCenterPos().distanceTo(maybePosition.get().toCenterPos()) * 0.8)));
public void move(Trick trickSource, SpellContext ctx) throws BlunderException {
if (source.isPresent())
ctx.useMana(trickSource, (float)(32 + (ctx.getBlockPos().toCenterPos().distanceTo(source.get().toCenterPos()) * 0.8)));
}
}

0 comments on commit 3670e4a

Please sign in to comment.