Add step sequence and selector nodes

This commit is contained in:
shylie 2024-08-02 15:38:11 -04:00
parent 399026f903
commit 89af7a4f5e
9 changed files with 98 additions and 17 deletions

1
.gitattributes vendored
View File

@ -5,3 +5,4 @@ src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf src/generated/**/*.json text eol=lf
*.png filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text *.gif filter=lfs diff=lfs merge=lfs -text
*.pxc filter=lfs diff=lfs merge=lfs -text

View File

@ -8,9 +8,7 @@ import info.shylie.ashes.entity.AshenGolemEntity;
import info.shylie.ashes.item.RuneItem; import info.shylie.ashes.item.RuneItem;
import info.shylie.ashes.rune.param.BlockPosRune; import info.shylie.ashes.rune.param.BlockPosRune;
import info.shylie.ashes.rune.param.ItemRune; import info.shylie.ashes.rune.param.ItemRune;
import info.shylie.ashes.rune.task.MoveRune; import info.shylie.ashes.rune.task.*;
import info.shylie.ashes.rune.task.SelectorRune;
import info.shylie.ashes.rune.task.SequenceRune;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -47,8 +45,11 @@ public class AshesRegistry {
public static final RegistryObject<RuneType<BlockPosRune>> BLOCK_POS_RUNE; public static final RegistryObject<RuneType<BlockPosRune>> BLOCK_POS_RUNE;
public static final RegistryObject<RuneType<ItemRune>> ITEM_RUNE; public static final RegistryObject<RuneType<ItemRune>> ITEM_RUNE;
public static final RegistryObject<RuneType<SelectorRune>> SELECTOR_RUNE;
public static final RegistryObject<RuneType<SequenceRune>> SEQUENCE_RUNE; public static final RegistryObject<RuneType<SequenceRune>> SEQUENCE_RUNE;
public static final RegistryObject<RuneType<SelectorRune>> SELECTOR_RUNE;
public static final RegistryObject<RuneType<StepSequenceRune>> STEP_SEQUENCE_RUNE;
public static final RegistryObject<RuneType<StepSelectorRune>> STEP_SELECTOR_RUNE;
public static final RegistryObject<RuneType<MoveRune>> MOVE_RUNE; public static final RegistryObject<RuneType<MoveRune>> MOVE_RUNE;
static { static {
@ -61,11 +62,11 @@ public class AshesRegistry {
() -> new RuneItem(new Item.Properties()) () -> new RuneItem(new Item.Properties())
); );
ASHEN_GOLEM = RegistryManager.registerEntity( ASHEN_GOLEM = ENTITY_TYPES.register("ashen_golem",
"ashen_golem", () -> EntityType.Builder.of(AshenGolemEntity::new, MobCategory.MISC)
EntityType.Builder.of(AshenGolemEntity::new, MobCategory.CREATURE)
.sized(0.6F, 1.8F) .sized(0.6F, 1.8F)
.fireImmune() .fireImmune()
.build(Ashes.MODID + "ashen_golem")
); );
ASHEN_GOLEM_SPAWN_EGG = registerSpawnEgg(ASHEN_GOLEM, Misc.intColor(38, 38, 38), Misc.intColor(66, 66, 66)); ASHEN_GOLEM_SPAWN_EGG = registerSpawnEgg(ASHEN_GOLEM, Misc.intColor(38, 38, 38), Misc.intColor(66, 66, 66));
@ -86,6 +87,9 @@ public class AshesRegistry {
SEQUENCE_RUNE = RUNES.register("sequence", RuneType.Builder.of(SequenceRune::new)::build); SEQUENCE_RUNE = RUNES.register("sequence", RuneType.Builder.of(SequenceRune::new)::build);
SELECTOR_RUNE = RUNES.register("selector", RuneType.Builder.of(SelectorRune::new)::build); SELECTOR_RUNE = RUNES.register("selector", RuneType.Builder.of(SelectorRune::new)::build);
STEP_SEQUENCE_RUNE = RUNES.register("step_sequence", RuneType.Builder.of(StepSequenceRune::new)::build);
STEP_SELECTOR_RUNE = RUNES.register("step_selector", RuneType.Builder.of(StepSelectorRune::new)::build);
MOVE_RUNE = RUNES.register("move", RuneType.Builder.of(MoveRune::new)::build); MOVE_RUNE = RUNES.register("move", RuneType.Builder.of(MoveRune::new)::build);
} }

View File

@ -53,10 +53,9 @@ public abstract class CompositeTaskRune extends TaskRune {
return status; return status;
} }
protected abstract Status updateImpl2(IGolem golem);
@Override @Override
protected final void saveImpl(CompoundTag tag) { protected final void saveImpl(CompoundTag tag) {
saveImpl2(tag);
ListTag listTag = new ListTag(); ListTag listTag = new ListTag();
for (TaskRune child : children) { for (TaskRune child : children) {
CompoundTag childTag = new CompoundTag(); CompoundTag childTag = new CompoundTag();
@ -68,9 +67,14 @@ public abstract class CompositeTaskRune extends TaskRune {
@Override @Override
protected final void loadImpl(CompoundTag tag) { protected final void loadImpl(CompoundTag tag) {
loadImpl2(tag);
ListTag list = tag.getList(CHILDREN_TAG, Tag.TAG_COMPOUND); ListTag list = tag.getList(CHILDREN_TAG, Tag.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
add(Rune.of(list.getCompound(i), TaskRune.class)); add(Rune.of(list.getCompound(i), TaskRune.class));
} }
} }
protected abstract Status updateImpl2(IGolem golem);
protected void saveImpl2(CompoundTag tag) { }
protected void loadImpl2(CompoundTag tag) { }
} }

View File

@ -15,6 +15,7 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.AbstractGolem; import net.minecraft.world.entity.animal.AbstractGolem;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.ForgeMod;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class AshenGolemEntity extends AbstractGolem implements IGolem { public class AshenGolemEntity extends AbstractGolem implements IGolem {
@ -26,11 +27,12 @@ public class AshenGolemEntity extends AbstractGolem implements IGolem {
public static AttributeSupplier.Builder createAttributes() { public static AttributeSupplier.Builder createAttributes() {
return AbstractGolem.createLivingAttributes() return AbstractGolem.createLivingAttributes()
.add(Attributes.MOVEMENT_SPEED, 0.5) .add(Attributes.MOVEMENT_SPEED, 0.25)
.add(Attributes.MAX_HEALTH, 30.0) .add(Attributes.MAX_HEALTH, 30.0)
.add(Attributes.FOLLOW_RANGE, 8.0) .add(Attributes.FOLLOW_RANGE, 32.0)
.add(Attributes.ARMOR, 6.0) .add(Attributes.ARMOR, 6.0)
.add(Attributes.KNOCKBACK_RESISTANCE, 1.0); .add(Attributes.KNOCKBACK_RESISTANCE, 1.0)
.add(ForgeMod.STEP_HEIGHT_ADDITION.get(), 0.5);
} }
@Nullable @Nullable
@ -62,7 +64,7 @@ public class AshenGolemEntity extends AbstractGolem implements IGolem {
@Override @Override
public void addAdditionalSaveData(CompoundTag tag) { public void addAdditionalSaveData(CompoundTag tag) {
task.save(tag); if (task != null) { task.save(tag); }
} }
@Override @Override

View File

@ -72,9 +72,12 @@ public class RuneItem extends Item {
@Override @Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) { public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) {
if (entity instanceof IGolem golem) { if (entity instanceof IGolem golem) {
golem.setTask(Rune.of(stack.getTag(), TaskRune.class)); TaskRune task = Rune.of(stack.getTag(), TaskRune.class);
if (task != null) {
golem.setTask(task);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
}
} }
return InteractionResult.PASS; return InteractionResult.PASS;

View File

@ -42,7 +42,7 @@ public class MoveRune extends LeafTaskRune {
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(), pos.getY() + 1,
pos.getZ(), pos.getZ(),
1.0 1.0
); );

View File

@ -0,0 +1,32 @@
package info.shylie.ashes.rune.task;
import info.shylie.ashes.api.golem.IGolem;
import info.shylie.ashes.api.rune.CompositeTaskRune;
import info.shylie.ashes.api.rune.RuneType;
public class StepSelectorRune extends CompositeTaskRune {
private int current;
public StepSelectorRune(RuneType<? extends StepSelectorRune> type) {
super(type);
}
@Override
protected boolean startImpl(IGolem golem) {
current = 0;
return true;
}
@Override
protected Status updateImpl2(IGolem golem) {
while (current < children.size()) {
Status status = children.get(current).update(golem);
if (status != Status.FAILURE) {
return status;
}
current++;
}
return Status.FAILURE;
}
}

View File

@ -0,0 +1,33 @@
package info.shylie.ashes.rune.task;
import info.shylie.ashes.api.golem.IGolem;
import info.shylie.ashes.api.rune.CompositeTaskRune;
import info.shylie.ashes.api.rune.RuneType;
public class StepSequenceRune extends CompositeTaskRune {
private int current;
public StepSequenceRune(RuneType<? extends StepSequenceRune> type) {
super(type);
}
@Override
protected boolean startImpl(IGolem golem) {
current = 0;
return true;
}
@Override
protected Status updateImpl2(IGolem golem) {
while (current < children.size()) {
Status status = children.get(current).update(golem);
if (status != Status.SUCCESS) {
return status;
}
current++;
}
return Status.SUCCESS;
}
}

BIN
src/main/resources/assets/ashes.pxc (Stored with Git LFS)

File diff suppressed because one or more lines are too long