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() { public Component getTooltip() {
return Component.empty(); return null;
} }
public TooltipComponent getTooltipImage() { 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.Font;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; 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.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class SingleItemTooltip implements TooltipComponent { public class SingleItemTooltip implements TooltipComponent {
private final Item item; private final Item item;
@ -15,6 +17,8 @@ public class SingleItemTooltip implements TooltipComponent {
} }
public static class SingleItemClientTooltip implements ClientTooltipComponent { public static class SingleItemClientTooltip implements ClientTooltipComponent {
private static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/gui/container/bundle.png");
SingleItemTooltip tooltip; SingleItemTooltip tooltip;
public SingleItemClientTooltip(SingleItemTooltip tooltip) { public SingleItemClientTooltip(SingleItemTooltip tooltip) {
@ -23,17 +27,18 @@ public class SingleItemTooltip implements TooltipComponent {
@Override @Override
public int getHeight() { public int getHeight() {
return 18; return 20;
} }
@Override @Override
public int getWidth(Font font) { public int getWidth(Font font) {
return 18; return 20;
} }
@Override @Override
public void renderImage(Font font, int x, int y, GuiGraphics graphics) { 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,9 +37,13 @@ public class BlockPosRune extends ParameterRune<BlockPos> {
@Override @Override
protected BlockPos loadImpl2(CompoundTag tag) { protected BlockPos loadImpl2(CompoundTag 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 new BlockPos(tag.getInt(X_TAG), tag.getInt(Y_TAG), tag.getInt(Z_TAG));
} }
return null;
}
@Override @Override
protected BlockPos calculate(UseOnContext context) { protected BlockPos calculate(UseOnContext context) {
return context.getClickedPos(); return context.getClickedPos();

View File

@ -36,6 +36,9 @@ public class ItemRune extends ParameterRune<Item> {
@Override @Override
protected void saveImpl(CompoundTag tag) { 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()); 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) { private boolean path(IGolem golem) {
BlockPos pos = getValue(0); BlockPos pos = getValue(0);
return pos != null && golem.asEntity().getNavigation().moveTo( return pos != null && golem.asEntity().getNavigation().moveTo(
pos.getX(), pos.getX(),
pos.getY() + 1, pos.getY(),
pos.getZ(), pos.getZ(),
1.0 1.0
); );