add item command, remove legacy ids
This commit is contained in:
parent
678f37e184
commit
1dea7e9645
38 changed files with 272 additions and 197 deletions
|
@ -110,9 +110,8 @@ public abstract class RotationRegistry {
|
|||
}
|
||||
}
|
||||
if(!values.isEmpty()) {
|
||||
int legacyId = common.init.BlockRegistry.getIdFromBlock(block);
|
||||
Rotation state = new Rotation(values.toArray(new RotationValue[values.size()]), predicate);
|
||||
// Log.CONFIG.debug("Block " + game.init.BlockRegistry.REGISTRY.getNameForObject(block) + "/" + legacyId + " mask = " + String.format("0x%x", mask));
|
||||
// Log.CONFIG.debug("Block " + game.init.BlockRegistry.getNameFromBlock(block) + "/" + legacyId + " mask = " + String.format("0x%x", mask));
|
||||
// for(RotationValue value : values) {
|
||||
// Log.CONFIG.debug(" meta " + value.data + " -> " + value.direction.toString());
|
||||
// }
|
||||
|
|
|
@ -192,6 +192,14 @@ public abstract class Command implements Executable {
|
|||
return this.addParameter(new PlayerEntityParser(name, defaulted, policy));
|
||||
}
|
||||
|
||||
protected Command addPlayerEntityList(String name, boolean defaulted, UserPolicy policy) {
|
||||
return this.addParameter(new PlayerEntityListParser(name, defaulted, policy));
|
||||
}
|
||||
|
||||
protected Command addPlayerEntityList(String name, char shortName, boolean defaulted, UserPolicy policy) {
|
||||
return this.addParameter(shortName, new PlayerEntityListParser(name, defaulted, policy));
|
||||
}
|
||||
|
||||
protected Command addEntity(String name, boolean defaulted, UserPolicy policy) {
|
||||
return this.addParameter(new EntityParser(name, defaulted, false, policy));
|
||||
}
|
||||
|
|
|
@ -266,6 +266,7 @@ public class CommandEnvironment {
|
|||
this.registerExecutable(new CommandSv());
|
||||
this.registerExecutable(new CommandClear());
|
||||
this.registerExecutable(new CommandEntity());
|
||||
this.registerExecutable(new CommandItem());
|
||||
|
||||
this.registerExecutable(new CommandHelp(this));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package server.command.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.ItemRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.tags.TagObject;
|
||||
import server.command.Command;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.Executor;
|
||||
import server.command.RunException;
|
||||
import server.command.StringCompleter;
|
||||
import server.command.UserPolicy;
|
||||
|
||||
public class CommandItem extends Command {
|
||||
public CommandItem() {
|
||||
super("item");
|
||||
|
||||
this.addString("item", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
return ItemRegistry.REGISTRY.getKeys();
|
||||
}
|
||||
});
|
||||
this.setParamsOptional();
|
||||
this.addInt("amount", 1, ItemStack.MAX_SIZE, 1);
|
||||
this.addTag("tag", 't');
|
||||
this.setParamsRequired();
|
||||
this.addPlayerEntityList("players", 'p', true, UserPolicy.NON_ADMINS_OR_SELF);
|
||||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String item, int amount, TagObject tag, List<EntityNPC> players) {
|
||||
ItemStack stack = ItemRegistry.getFromIdName(item, null);
|
||||
if(stack == null)
|
||||
throw new RunException("Gegenstand '%s' existiert nicht", item);
|
||||
stack.setTagCompound(tag);
|
||||
int done = 0;
|
||||
int given = 0;
|
||||
for(EntityNPC player : players) {
|
||||
int total = amount;
|
||||
while(total > 0) {
|
||||
int added = Math.min(total, stack.getMaxStackSize());
|
||||
ItemStack st = stack.copy();
|
||||
st.size = added;
|
||||
player.inventory.addItemStackToInventory(st);
|
||||
added -= st.size;
|
||||
if(added <= 0)
|
||||
break;
|
||||
total -= added;
|
||||
}
|
||||
total = amount - total;
|
||||
if(total <= 0)
|
||||
continue;
|
||||
exec.logConsole("%d * %s zum Inventar von %s hinzugefügt", total, stack.getDisplayName(), player.getCommandName());
|
||||
done++;
|
||||
given += total;
|
||||
}
|
||||
if(done > 1)
|
||||
exec.logConsole("%d * %s an %d Spieler verteilt", given, stack.getDisplayName(), done);
|
||||
return given;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package server.world;
|
||||
|
||||
import common.block.Block;
|
||||
import common.init.BlockRegistry;
|
||||
import common.util.BlockPos;
|
||||
|
||||
public class NextTickListEntry implements Comparable<NextTickListEntry>
|
||||
|
@ -62,11 +61,6 @@ public class NextTickListEntry implements Comparable<NextTickListEntry>
|
|||
return this.scheduledTime < p_compareTo_1_.scheduledTime ? -1 : (this.scheduledTime > p_compareTo_1_.scheduledTime ? 1 : (this.priority != p_compareTo_1_.priority ? this.priority - p_compareTo_1_.priority : (this.tickEntryID < p_compareTo_1_.tickEntryID ? -1 : (this.tickEntryID > p_compareTo_1_.tickEntryID ? 1 : 0))));
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return BlockRegistry.getIdFromBlock(this.block) + ": " + this.position + ", " + this.scheduledTime + ", " + this.priority + ", " + this.tickEntryID;
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.block;
|
||||
|
|
|
@ -23,6 +23,7 @@ import common.collect.Lists;
|
|||
import common.collect.Maps;
|
||||
import common.entity.Entity;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.init.EntityRegistry;
|
||||
import common.log.Log;
|
||||
import common.tags.TagObject;
|
||||
|
@ -455,22 +456,14 @@ public class Region {
|
|||
int invalid = 0;
|
||||
for(int n = 0; n < ticks.size(); ++n) {
|
||||
TagObject tick = ticks.get(n);
|
||||
Block block;
|
||||
Block block = BlockRegistry.getRegisteredBlock(tick.getString("i"));
|
||||
|
||||
if(tick.hasString("i")) {
|
||||
block = BlockRegistry.getByIdFallback(tick.getString("i"));
|
||||
}
|
||||
else {
|
||||
block = BlockRegistry.getBlockById(tick.getInt("i"));
|
||||
}
|
||||
|
||||
if(block != null) { // FIX
|
||||
if(block != Blocks.air) { // FIX
|
||||
world.scheduleBlockUpdate(new BlockPos(tick.getInt("x"), tick.getInt("y"), tick.getInt("z")), block,
|
||||
tick.getInt("t"), tick.getInt("p"));
|
||||
}
|
||||
else if(invalid++ < 10) {
|
||||
Log.IO.warn("Unbekannter Block-Tick in Chunk " + x + "," + z + ": " +
|
||||
(tick.hasString("i") ? ("'" + tick.getString("i") + "'") : ("#" + tick.getInt("i"))));
|
||||
Log.IO.warn("Unbekannter Block-Tick in Chunk " + x + "," + z + ": '" + tick.getString("i") + "'");
|
||||
}
|
||||
}
|
||||
if(invalid > 10) {
|
||||
|
@ -573,9 +566,11 @@ public class Region {
|
|||
List<TagObject> ticks = Lists.newArrayList();
|
||||
|
||||
for(NextTickListEntry tic : tics) {
|
||||
if(tic.getBlock() == Blocks.air)
|
||||
continue;
|
||||
TagObject tick = new TagObject();
|
||||
String res = BlockRegistry.REGISTRY.getNameForObject(tic.getBlock());
|
||||
tick.setString("i", res == null ? "" : res.toString());
|
||||
String res = BlockRegistry.getNameFromBlock(tic.getBlock());
|
||||
tick.setString("i", res == null ? "" : res);
|
||||
tick.setInt("x", tic.position.getX());
|
||||
tick.setInt("y", tic.position.getY());
|
||||
tick.setInt("z", tic.position.getZ());
|
||||
|
|
|
@ -406,19 +406,19 @@ public class StructureVillage
|
|||
protected void writeTags(TagObject tagCompound)
|
||||
{
|
||||
super.writeTags(tagCompound);
|
||||
tagCompound.setInt("CA", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeA));
|
||||
tagCompound.setInt("CB", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeB));
|
||||
tagCompound.setInt("CC", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeC));
|
||||
tagCompound.setInt("CD", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeD));
|
||||
tagCompound.setString("CA", BlockRegistry.getNameFromBlock(this.cropTypeA));
|
||||
tagCompound.setString("CB", BlockRegistry.getNameFromBlock(this.cropTypeB));
|
||||
tagCompound.setString("CC", BlockRegistry.getNameFromBlock(this.cropTypeC));
|
||||
tagCompound.setString("CD", BlockRegistry.getNameFromBlock(this.cropTypeD));
|
||||
}
|
||||
|
||||
protected void readTags(TagObject tagCompound)
|
||||
{
|
||||
super.readTags(tagCompound);
|
||||
this.cropTypeA = BlockRegistry.getBlockById(tagCompound.getInt("CA"));
|
||||
this.cropTypeB = BlockRegistry.getBlockById(tagCompound.getInt("CB"));
|
||||
this.cropTypeC = BlockRegistry.getBlockById(tagCompound.getInt("CC"));
|
||||
this.cropTypeD = BlockRegistry.getBlockById(tagCompound.getInt("CD"));
|
||||
this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA"));
|
||||
this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB"));
|
||||
this.cropTypeC = BlockRegistry.getRegisteredBlock(tagCompound.getString("CC"));
|
||||
this.cropTypeD = BlockRegistry.getRegisteredBlock(tagCompound.getString("CD"));
|
||||
}
|
||||
|
||||
private Block func_151559_a(Random rand)
|
||||
|
@ -515,15 +515,15 @@ public class StructureVillage
|
|||
protected void writeTags(TagObject tagCompound)
|
||||
{
|
||||
super.writeTags(tagCompound);
|
||||
tagCompound.setInt("CA", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeA));
|
||||
tagCompound.setInt("CB", BlockRegistry.REGISTRY.getIDForObject(this.cropTypeB));
|
||||
tagCompound.setString("CA", BlockRegistry.getNameFromBlock(this.cropTypeA));
|
||||
tagCompound.setString("CB", BlockRegistry.getNameFromBlock(this.cropTypeB));
|
||||
}
|
||||
|
||||
protected void readTags(TagObject tagCompound)
|
||||
{
|
||||
super.readTags(tagCompound);
|
||||
this.cropTypeA = BlockRegistry.getBlockById(tagCompound.getInt("CA"));
|
||||
this.cropTypeB = BlockRegistry.getBlockById(tagCompound.getInt("CB"));
|
||||
this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA"));
|
||||
this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB"));
|
||||
}
|
||||
|
||||
private Block func_151560_a(Random rand)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue