This commit is contained in:
Sen 2025-07-11 15:39:08 +02:00
parent b3f7b5a07b
commit b6242d5de1
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
5 changed files with 98 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Before After
Before After

View file

@ -97,7 +97,7 @@ public abstract class SpeciesRegistry {
registerSpecies("Elf", EntityElf.class, "gharoth", "Elbe", 0x054100, 0xd2d2d2, ":highelf", "Thranduil", 0x82888b, 0xeae7bd); registerSpecies("Elf", EntityElf.class, "gharoth", "Elbe", 0x054100, 0xd2d2d2, ":highelf", "Thranduil", 0x82888b, 0xeae7bd);
registerSpecies("WoodElf", EntityWoodElf.class, "gharoth", "Waldelbe", 0x054100, 0x00bb00); registerSpecies("WoodElf", EntityWoodElf.class, "gharoth", "Waldelbe", 0x054100, 0x00bb00);
registerSpecies("BloodElf", EntityBloodElf.class, "kyroth", "Blutelbe", 0x054100, 0x960000); registerSpecies("BloodElf", EntityBloodElf.class, "kyroth", "Blutelbe", 0x054100, 0x960000);
registerSpecies("Human", EntityHuman.class, EntityHuman.ClassType.class, "terra", "NSC", 0x4f7d9a, 0x034c7a, registerSpecies("Human", EntityHuman.class, EntityHuman.ClassType.class, "terra", "Mensch", 0x4f7d9a, 0x034c7a,
EntityHuman.ClassType.KNIGHT, EntityHuman.ClassType.KNIGHT,
":knight_1", ":knight_2", ":knight_3", ":knight_1", ":knight_2", ":knight_3",
":knight_4", ":knight_5", ":knight_6", ":knight_7", ":knight_8", EntityHuman.ClassType.PEASANT, ":knight_4", ":knight_5", ":knight_6", ":knight_7", ":knight_8", EntityHuman.ClassType.PEASANT,

View file

@ -279,5 +279,7 @@ public class CommandEnvironment {
this.registerExecutable(new CommandEffect()); this.registerExecutable(new CommandEffect());
this.registerExecutable(new CommandExterminatus()); this.registerExecutable(new CommandExterminatus());
this.registerExecutable(new CommandReset()); this.registerExecutable(new CommandReset());
this.registerExecutable(new CommandSet());
} }
} }

View file

@ -0,0 +1,87 @@
package server.command.commands;
import java.util.Collection;
import common.block.Block;
import common.collect.Iterables;
import common.collect.Lists;
import common.init.BlockRegistry;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.util.BlockPos.MutableBlockPos;
import common.world.State;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.command.StringCompleter;
import server.network.Player;
import server.world.WorldServer;
public class CommandSet extends Command {
public CommandSet() {
super("set");
this.setParamsOptional();
this.addString("block", false, new StringCompleter() {
public Collection<String> complete(CommandEnvironment env, String last) {
int idx = last.indexOf(',');
if(idx >= 0) {
Block block = BlockRegistry.byNameExact(last.substring(0, idx));
if(block != null)
return Lists.newArrayList(Iterables.transform(block.getSavedStates(), state -> BlockRegistry.getName(state)));
}
return BlockRegistry.getKeys();
}
});
this.addTag("tag", 't');
}
public Object exec(CommandEnvironment env, Executor exec, String block, TagObject tag) {
if(!exec.isPlayer() || ((Player)exec).getPresentEntity() == null)
throw new RunException("Nur Spieler können diesen Befehl ausführen");
Player player = (Player)exec;
Iterable<MutableBlockPos> blocks = player.getSelectedBlocks();
if(blocks == null)
throw new RunException("Es ist keine Auswahl vorhanden");
State state;
if(block == null) {
if(player.getPresentEntity().getHeldItem() == null)
throw new RunException("Es befindet sich kein Gegenstand in der Hand");
else if(player.getPresentEntity().getHeldItem().getItem().getBlock() == null)
throw new RunException("Der Gegenstand in der Hand ist kein Block");
state = player.getPresentEntity().getHeldItem().getItem().getBlock().getState();
}
else {
state = BlockRegistry.byName(block, null);
if(state == null)
throw new RunException("Block '%s' existiert nicht", block);
}
WorldServer world = (WorldServer)player.getPresentEntity().getServerWorld();
int changed = 0;
for(MutableBlockPos pos : blocks) {
boolean success = world.setState(pos, state);
if(tag != null) {
TileEntity tile = world.getTileEntity(pos);
if(tile != null) {
TagObject te = new TagObject();
tile.writeTags(te);
te.merge(tag);
TileEntity newTile = TileEntity.createAndLoadEntity(world, world.getChunk(pos), pos, te);
if(newTile != null) {
world.removeTileEntity(pos);
world.setTileEntity(pos, newTile);
success = true;
}
}
}
if(success)
++changed;
}
if(changed > 0)
exec.log("%d * %s platziert", changed, state.getBlock().getDisplay());
else
exec.log("Es wurden keine Blöcke verändert");
return changed;
}
}

View file

@ -106,6 +106,7 @@ import common.tileentity.TileEntity;
import common.tileentity.TileEntityDevice; import common.tileentity.TileEntityDevice;
import common.tileentity.TileEntitySign; import common.tileentity.TileEntitySign;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BlockPos.MutableBlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.ChunkPos; import common.util.ChunkPos;
import common.util.ExtMath; import common.util.ExtMath;
@ -1486,6 +1487,13 @@ public class Player extends User implements Executor, IPlayer
return newValue; return newValue;
} }
public Iterable<MutableBlockPos> getSelectedBlocks() {
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != UniverseRegistry.getId(this.entity.worldObj.dimension) ||
this.selPos1 == null || this.selPos2 == null)
return null;
return BlockPos.getAllInBoxMutable(this.selPos1, this.selPos2);
}
private boolean copyClipboard() { private boolean copyClipboard() {
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != UniverseRegistry.getId(this.entity.worldObj.dimension) || if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != UniverseRegistry.getId(this.entity.worldObj.dimension) ||
this.selPos1 == null || this.selPos2 == null) this.selPos1 == null || this.selPos2 == null)