made impeti display messages when they print #473. Fixed some lang stuff.

This commit is contained in:
Talia-12 2023-06-13 01:44:47 +10:00
parent 0236a1f6fb
commit 045618fbc0
13 changed files with 63 additions and 38 deletions

View file

@ -59,9 +59,9 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
// these are null together
@Nullable
protected Component errorMsg = null;
protected Component displayMsg = null;
@Nullable
protected ItemStack errorDisplay = null;
protected ItemStack displayItem = null;
public BlockEntityAbstractImpetus(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
@ -73,29 +73,33 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
}
@Nullable
public Component getErrorMsg() {
return errorMsg;
public Component getDisplayMsg() {
return displayMsg;
}
public void clearError() {
this.errorMsg = null;
this.errorDisplay = null;
public void clearDisplay() {
this.displayMsg = null;
this.displayItem = null;
this.sync();
}
public void postError(Component error, ItemStack display) {
this.errorMsg = error;
this.errorDisplay = display;
public void postDisplay(Component error, ItemStack display) {
this.displayMsg = error;
this.displayItem = display;
this.sync();
}
public void postMishap(Component mishapDisplay) {
this.postError(mishapDisplay, new ItemStack(Items.MUSIC_DISC_11));
this.postDisplay(mishapDisplay, new ItemStack(Items.MUSIC_DISC_11));
}
public void postPrint(Component printDisplay) {
this.postDisplay(printDisplay, new ItemStack(Items.BOOK));
}
// Pull this out because we may need to call it both on startup and halfway thru
public void postNoExits(BlockPos pos) {
this.postError(
this.postDisplay(
Component.translatable("hexcasting.tooltip.circle.no_exit",
Component.literal(pos.toShortString()).withStyle(ChatFormatting.RED)),
new ItemStack(Items.OAK_SIGN));
@ -164,7 +168,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
this.postNoExits(this.getBlockPos());
} else {
ICircleComponent.sfx(errPos, this.level.getBlockState(errPos), this.level, null, false);
this.postError(Component.translatable("hexcasting.tooltip.circle.no_closure",
this.postDisplay(Component.translatable("hexcasting.tooltip.circle.no_closure",
Component.literal(errPos.toShortString()).withStyle(ChatFormatting.RED)),
new ItemStack(Items.LEAD));
}
@ -173,7 +177,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
}
this.executionState = result.unwrap();
this.clearError();
this.clearDisplay();
var serverLevel = (ServerLevel) this.level;
serverLevel.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(),
this.executionState.getTickSpeed());
@ -268,10 +272,10 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
tag.putLong(TAG_MEDIA, this.media);
if (this.errorMsg != null && this.errorDisplay != null) {
tag.putString(TAG_ERROR_MSG, Component.Serializer.toJson(this.errorMsg));
if (this.displayMsg != null && this.displayItem != null) {
tag.putString(TAG_ERROR_MSG, Component.Serializer.toJson(this.displayMsg));
var itemTag = new CompoundTag();
this.errorDisplay.save(itemTag);
this.displayItem.save(itemTag);
tag.put(TAG_ERROR_DISPLAY, itemTag);
}
}
@ -292,11 +296,11 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
if (tag.contains(TAG_ERROR_MSG, Tag.TAG_STRING) && tag.contains(TAG_ERROR_DISPLAY, Tag.TAG_COMPOUND)) {
var msg = Component.Serializer.fromJson(tag.getString(TAG_ERROR_MSG));
var display = ItemStack.of(tag.getCompound(TAG_ERROR_DISPLAY));
this.errorMsg = msg;
this.errorDisplay = display;
this.displayMsg = msg;
this.displayItem = display;
} else {
this.errorMsg = null;
this.errorDisplay = null;
this.displayMsg = null;
this.displayItem = null;
}
}
@ -312,8 +316,8 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), dustCmp));
}
if (this.errorMsg != null && this.errorDisplay != null) {
lines.add(new Pair<>(this.errorDisplay, this.errorMsg));
if (this.displayMsg != null && this.displayItem != null) {
lines.add(new Pair<>(this.displayItem, this.displayMsg));
}
}
}

View file

@ -247,7 +247,7 @@ public class CircleExecutionState {
&& cc.canEnterFromDirection(exit.getSecond(), exit.getFirst(), there, world)) {
if (found != null) {
// oh no!
impetus.postError(
impetus.postDisplay(
Component.translatable("hexcasting.tooltip.circle.many_exits",
Component.literal(this.currentPos.toShortString()).withStyle(ChatFormatting.RED)),
new ItemStack(Items.COMPASS));

View file

@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -291,4 +292,6 @@ public abstract class CastingEnvironment {
public abstract FrozenPigment getColorizer();
public abstract void produceParticles(ParticleSpray particles, FrozenPigment colorizer);
public abstract void printMessage(Component message);
}

View file

@ -12,6 +12,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexItems;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
@ -168,4 +169,12 @@ public class CircleCastEnv extends CastingEnvironment {
public void produceParticles(ParticleSpray particles, FrozenPigment colorizer) {
particles.sprayParticles(this.world, colorizer);
}
@Override
public void printMessage(Component message) {
var impetus = getImpetus();
if (impetus == null)
return;
impetus.postPrint(message);
}
}

View file

@ -16,6 +16,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.utils.MediaHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
@ -212,4 +213,9 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
// not sure what the diff between this and isCreative() is
return this.caster.getAbilities().instabuild;
}
@Override
public void printMessage(Component message) {
caster.sendSystemMessage(message);
}
}

View file

@ -107,10 +107,10 @@ public class BlockEntityRedstoneImpetus extends BlockEntityAbstractImpetus {
cachedDisplayStack = head;
}
lines.add(new Pair<>(cachedDisplayStack,
Component.translatable("hexcasting.tooltip.lens.impetus.storedplayer", name.getName())));
Component.translatable("hexcasting.tooltip.lens.impetus.redstone.bound", name.getName())));
} else {
lines.add(new Pair<>(new ItemStack(Items.BARRIER),
Component.translatable("hexcasting.tooltip.lens.impetus.storedplayer.none")));
Component.translatable("hexcasting.tooltip.lens.impetus.redstone.bound.none")));
}
}

View file

@ -60,7 +60,7 @@ public class BlockRedstoneImpetus extends BlockAbstractImpetus {
tile.setPlayer(player.getGameProfile(), entity.getUUID());
tile.sync();
pLevel.playSound(pPlayer, pPos, HexSounds.IMPETUS_STOREDPLAYER_DING,
pLevel.playSound(pPlayer, pPos, HexSounds.IMPETUS_REDSTONE_DING,
SoundSource.BLOCKS, 1f, 1f);
}
}

View file

@ -34,7 +34,7 @@ object OpPrint : Action {
private data class Spell(val datum: Iota) : RenderedSpell {
override fun cast(ctx: CastingEnvironment) {
ctx.caster?.sendSystemMessage(datum.display()) // TODO: how to handle in cirles
ctx.printMessage(datum.display())
}
}
}

View file

@ -41,7 +41,7 @@ public class HexSounds {
public static final SoundEvent SCROLL_SCRIBBLE = sound("scroll.scribble");
public static final SoundEvent IMPETUS_LOOK_TICK = sound("impetus.fletcher.tick");
public static final SoundEvent IMPETUS_STOREDPLAYER_DING = sound("impetus.cleric.register");
public static final SoundEvent IMPETUS_REDSTONE_DING = sound("impetus.redstone.register");
public static final SoundEvent READ_LORE_FRAGMENT = sound("lore_fragment.read");

View file

@ -300,16 +300,19 @@
no_closure: "The flow of media will not be able to return to the impetus at %s"
},
impetus: {
"redstone.bound": "Bound to %s",
"redstone.bound.none": "Unbound",
},
lens: {
impetus: {
"redstone.bound": "Bound to %s",
"redstone.bound.none": "Unbound",
},
"pattern.invalid": "Invalid Pattern",
"akashic.bookshelf.location": "Record at %s",
"akashic.record.count": "%s iotas stored",
"akashic.record.count.single": "%s iota stored",
"bee": "%s bees",
"bee.single": "%s bee",
},
"brainsweep.min_level": "Level %s or higher",
@ -362,7 +365,7 @@
"scroll.dust": "Scroll covers with dust",
"scroll.scribble": "Scroll is scribbled",
"impetus.fletcher.tick": "Fletcher Impetus ticks",
"impetus.cleric.register": "Cleric Impetus dings",
"impetus.redstone.register": "Cleric Impetus dings",
"lore_fragment.read": "Read lore fragment",
"flight.ambience": "Player flies",
"flight.finish": "Flight ends",

View file

@ -170,7 +170,7 @@
"hexcasting.subtitles.scroll.dust": "Свиток покрывается пылью",
"hexcasting.subtitles.scroll.scribble": "Свиток очищен",
"hexcasting.subtitles.impetus.fletcher.tick": "Fletcher Impetus ticks",
"hexcasting.subtitles.impetus.cleric.register": "Cleric Impetus dings",
"hexcasting.subtitles.redstone.cleric.register": "Cleric Impetus dings",
"hexcasting.spell.hexcasting:get_caster": "Зеркало нарцисса",
"hexcasting.spell.hexcasting:get_entity_pos": "Положение сущности",

View file

@ -298,7 +298,7 @@
"hexcasting.subtitles.scroll.dust": "卷轴:被施粉",
"hexcasting.subtitles.scroll.scribble": "卷轴:被涂写",
"hexcasting.subtitles.impetus.fletcher.tick": "制箭师促动石:咔哒",
"hexcasting.subtitles.impetus.cleric.register": "牧师促动石:叮~",
"hexcasting.subtitles.impetus.redstone.register": "牧师促动石:叮~",
"hexcasting.subtitles.lore_fragment.read": "故事残卷:被阅读",
"hexcasting.subtitles.flight.ambience": "玩家:飞翔",
"hexcasting.subtitles.flight.finish": "飞翔结束",

View file

@ -126,11 +126,11 @@
],
"subtitle": "hexcasting.subtitles.impetus.fletcher.tick"
},
"impetus.cleric.register": {
"impetus.redstone.register": {
"sounds": [
"minecraft:random/orb"
],
"subtitle": "hexcasting.subtitles.impetus.cleric.register"
"subtitle": "hexcasting.subtitles.impetus.redstone.register"
},
"lore_fragment.read": {