use of net.minecraft.tileentity.CommandBlockBaseLogic in project SpongeCommon by SpongePowered.
the class EntityCommandDataProcessor method getValues.
@Override
protected Map<Key<?>, ?> getValues(EntityMinecartCommandBlock entity) {
CommandBlockBaseLogic logic = entity.getCommandBlockLogic();
Map<Key<?>, Object> values = Maps.newHashMapWithExpectedSize(4);
Optional<Text> lastCommandOutput = logic.getLastOutput() != null ? Optional.of(SpongeTexts.toText(logic.getLastOutput())) : Optional.empty();
values.put(Keys.LAST_COMMAND_OUTPUT, lastCommandOutput);
values.put(Keys.COMMAND, logic.commandStored);
values.put(Keys.SUCCESS_COUNT, logic.successCount);
values.put(Keys.TRACKS_OUTPUT, logic.shouldTrackOutput());
return values;
}
use of net.minecraft.tileentity.CommandBlockBaseLogic in project SpongeCommon by SpongePowered.
the class TileEntityCommandDataProcessor method set.
@SuppressWarnings("unchecked")
@Override
protected boolean set(TileEntityCommandBlock entity, Map<Key<?>, Object> keyValues) {
CommandBlockBaseLogic logic = entity.getCommandBlockLogic();
logic.setLastOutput(SpongeTexts.toComponent(((Optional<Text>) keyValues.get(Keys.LAST_COMMAND_OUTPUT)).orElse(Text.of())));
logic.commandStored = (String) keyValues.get(Keys.COMMAND);
logic.successCount = (int) keyValues.get(Keys.SUCCESS_COUNT);
logic.setTrackOutput((boolean) keyValues.get(Keys.TRACKS_OUTPUT));
entity.markDirty();
return true;
}
use of net.minecraft.tileentity.CommandBlockBaseLogic in project SpongeCommon by SpongePowered.
the class SpongeCommandBlockBuilder method buildContent.
@Override
protected Optional<CommandBlock> buildContent(DataView container) throws InvalidDataException {
return super.buildContent(container).flatMap(commandBlock -> {
if (!container.contains(DataQueries.STORED_COMMAND, DataQueries.SUCCESS_COUNT, DataQueries.DOES_TRACK_OUTPUT)) {
((TileEntity) commandBlock).invalidate();
return Optional.empty();
}
CommandBlockBaseLogic cmdBlockLogic = ((TileEntityCommandBlock) commandBlock).getCommandBlockLogic();
cmdBlockLogic.setCommand(container.getString(DataQueries.STORED_COMMAND).get());
cmdBlockLogic.successCount = container.getInt(DataQueries.SUCCESS_COUNT).get();
cmdBlockLogic.setTrackOutput(container.getBoolean(DataQueries.DOES_TRACK_OUTPUT).get());
if (cmdBlockLogic.shouldTrackOutput()) {
cmdBlockLogic.setLastOutput(SpongeTexts.toComponent(SpongeTexts.fromLegacy(container.getString(DataQueries.TRACKED_OUTPUT).get())));
}
((TileEntityCommandBlock) commandBlock).validate();
return Optional.of(commandBlock);
});
}
use of net.minecraft.tileentity.CommandBlockBaseLogic in project SpongeCommon by SpongePowered.
the class EntityCommandDataProcessor method set.
@SuppressWarnings("unchecked")
@Override
protected boolean set(EntityMinecartCommandBlock entity, Map<Key<?>, Object> keyValues) {
CommandBlockBaseLogic logic = entity.getCommandBlockLogic();
logic.setLastOutput(SpongeTexts.toComponent(((Optional<Text>) keyValues.get(Keys.LAST_COMMAND_OUTPUT)).orElse(Text.of())));
logic.commandStored = (String) keyValues.get(Keys.COMMAND);
logic.successCount = (int) keyValues.get(Keys.SUCCESS_COUNT);
logic.setTrackOutput((boolean) keyValues.get(Keys.TRACKS_OUTPUT));
entity.onUpdate();
return true;
}
use of net.minecraft.tileentity.CommandBlockBaseLogic in project SpongeCommon by SpongePowered.
the class TileEntityCommandDataProcessor method getValues.
@Override
protected Map<Key<?>, ?> getValues(TileEntityCommandBlock entity) {
CommandBlockBaseLogic logic = entity.getCommandBlockLogic();
Map<Key<?>, Object> values = Maps.newHashMapWithExpectedSize(4);
Optional<Text> lastCommandOutput = logic.getLastOutput() != null ? Optional.of(SpongeTexts.toText(logic.getLastOutput())) : Optional.empty();
values.put(Keys.LAST_COMMAND_OUTPUT, lastCommandOutput);
values.put(Keys.COMMAND, logic.commandStored);
values.put(Keys.SUCCESS_COUNT, logic.successCount);
values.put(Keys.TRACKS_OUTPUT, logic.shouldTrackOutput());
return values;
}
Aggregations