Search in sources :

Example 1 with CommandBlockBaseLogic

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;
}
Also used : CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) Text(org.spongepowered.api.text.Text) Key(org.spongepowered.api.data.key.Key)

Example 2 with CommandBlockBaseLogic

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;
}
Also used : CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) Optional(java.util.Optional)

Example 3 with CommandBlockBaseLogic

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);
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) TileEntityCommandBlock(net.minecraft.tileentity.TileEntityCommandBlock)

Example 4 with CommandBlockBaseLogic

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;
}
Also used : CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) Optional(java.util.Optional)

Example 5 with CommandBlockBaseLogic

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;
}
Also used : CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) Text(org.spongepowered.api.text.Text) Key(org.spongepowered.api.data.key.Key)

Aggregations

CommandBlockBaseLogic (net.minecraft.tileentity.CommandBlockBaseLogic)5 Optional (java.util.Optional)2 Key (org.spongepowered.api.data.key.Key)2 Text (org.spongepowered.api.text.Text)2 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityCommandBlock (net.minecraft.tileentity.TileEntityCommandBlock)1