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
*.png 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.rune.param.BlockPosRune;
import info.shylie.ashes.rune.param.ItemRune;
import info.shylie.ashes.rune.task.MoveRune;
import info.shylie.ashes.rune.task.SelectorRune;
import info.shylie.ashes.rune.task.SequenceRune;
import info.shylie.ashes.rune.task.*;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
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<ItemRune>> ITEM_RUNE;
public static final RegistryObject<RuneType<SelectorRune>> SELECTOR_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;
static {
@ -61,11 +62,11 @@ public class AshesRegistry {
() -> new RuneItem(new Item.Properties())
);
ASHEN_GOLEM = RegistryManager.registerEntity(
"ashen_golem",
EntityType.Builder.of(AshenGolemEntity::new, MobCategory.CREATURE)
ASHEN_GOLEM = ENTITY_TYPES.register("ashen_golem",
() -> EntityType.Builder.of(AshenGolemEntity::new, MobCategory.MISC)
.sized(0.6F, 1.8F)
.fireImmune()
.build(Ashes.MODID + "ashen_golem")
);
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);
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);
}

View File

@ -53,10 +53,9 @@ public abstract class CompositeTaskRune extends TaskRune {
return status;
}
protected abstract Status updateImpl2(IGolem golem);
@Override
protected final void saveImpl(CompoundTag tag) {
saveImpl2(tag);
ListTag listTag = new ListTag();
for (TaskRune child : children) {
CompoundTag childTag = new CompoundTag();
@ -68,9 +67,14 @@ public abstract class CompositeTaskRune extends TaskRune {
@Override
protected final void loadImpl(CompoundTag tag) {
loadImpl2(tag);
ListTag list = tag.getList(CHILDREN_TAG, Tag.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) {
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.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.ForgeMod;
import org.jetbrains.annotations.Nullable;
public class AshenGolemEntity extends AbstractGolem implements IGolem {
@ -26,11 +27,12 @@ public class AshenGolemEntity extends AbstractGolem implements IGolem {
public static AttributeSupplier.Builder createAttributes() {
return AbstractGolem.createLivingAttributes()
.add(Attributes.MOVEMENT_SPEED, 0.5)
.add(Attributes.MOVEMENT_SPEED, 0.25)
.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.KNOCKBACK_RESISTANCE, 1.0);
.add(Attributes.KNOCKBACK_RESISTANCE, 1.0)
.add(ForgeMod.STEP_HEIGHT_ADDITION.get(), 0.5);
}
@Nullable
@ -62,7 +64,7 @@ public class AshenGolemEntity extends AbstractGolem implements IGolem {
@Override
public void addAdditionalSaveData(CompoundTag tag) {
task.save(tag);
if (task != null) { task.save(tag); }
}
@Override

View File

@ -72,9 +72,12 @@ public class RuneItem extends Item {
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) {
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;

View File

@ -42,7 +42,7 @@ public class MoveRune extends LeafTaskRune {
BlockPos pos = getValue(0);
return pos != null && golem.asEntity().getNavigation().moveTo(
pos.getX(),
pos.getY(),
pos.getY() + 1,
pos.getZ(),
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