Fix movement always succeeding even if target was not reached

This commit is contained in:
shylie 2024-08-03 13:15:46 -04:00
parent 89af7a4f5e
commit a2ef7e870c
5 changed files with 29 additions and 8 deletions

View File

@ -21,7 +21,7 @@ public abstract class Rune {
}
public Component getTooltip() {
return Component.empty();
return null;
}
public TooltipComponent getTooltipImage() {

View File

@ -3,9 +3,11 @@ package info.shylie.ashes.api.tooltip;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class SingleItemTooltip implements TooltipComponent {
private final Item item;
@ -15,6 +17,8 @@ public class SingleItemTooltip implements TooltipComponent {
}
public static class SingleItemClientTooltip implements ClientTooltipComponent {
private static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/gui/container/bundle.png");
SingleItemTooltip tooltip;
public SingleItemClientTooltip(SingleItemTooltip tooltip) {
@ -23,17 +27,18 @@ public class SingleItemTooltip implements TooltipComponent {
@Override
public int getHeight() {
return 18;
return 20;
}
@Override
public int getWidth(Font font) {
return 18;
return 20;
}
@Override
public void renderImage(Font font, int x, int y, GuiGraphics graphics) {
graphics.renderFakeItem(new ItemStack(tooltip.item), x, y);
graphics.blit(TEXTURE_LOCATION, x, y, 0, 0, 0, 18, 18, 128, 128);
graphics.renderFakeItem(new ItemStack(tooltip.item), x + 1, y + 1);
}
}
}

View File

@ -37,7 +37,11 @@ public class BlockPosRune extends ParameterRune<BlockPos> {
@Override
protected BlockPos loadImpl2(CompoundTag tag) {
return new BlockPos(tag.getInt(X_TAG), tag.getInt(Y_TAG), tag.getInt(Z_TAG));
if (tag.contains(X_TAG) && tag.contains(Y_TAG) && tag.contains(Z_TAG)) {
return new BlockPos(tag.getInt(X_TAG), tag.getInt(Y_TAG), tag.getInt(Z_TAG));
}
return null;
}
@Override

View File

@ -36,6 +36,9 @@ public class ItemRune extends ParameterRune<Item> {
@Override
protected void saveImpl(CompoundTag tag) {
tag.putString(ITEM_TAG, ForgeRegistries.ITEMS.getKey(getValue()).toString());
ResourceLocation rl = ForgeRegistries.ITEMS.getKey(getValue());
if (rl != null) {
tag.putString(ITEM_TAG, rl.toString());
}
}
}

View File

@ -35,14 +35,23 @@ public class MoveRune extends LeafTaskRune {
);
e.move(MoverType.SELF, e.getDeltaMovement());
return e.getNavigation().isDone() ? Status.SUCCESS : Status.ONGOING;
if (e.getNavigation().isDone()) {
BlockPos pos = getValue(0);
if (e.position().distanceToSqr(new Vec3(pos.getX(), pos.getY() + 1, pos.getZ())) < 1) {
return Status.SUCCESS;
}
return Status.FAILURE;
}
return Status.ONGOING;
}
private boolean path(IGolem golem) {
BlockPos pos = getValue(0);
return pos != null && golem.asEntity().getNavigation().moveTo(
pos.getX(),
pos.getY() + 1,
pos.getY(),
pos.getZ(),
1.0
);