fix: more random fixes
This commit is contained in:
parent
8ceebae43f
commit
f5e073f5cc
|
@ -24,6 +24,7 @@ public class ItemWrench extends ItemBase implements IToolConfigurator {
|
|||
|
||||
public void wrenchUsed(EntityPlayer entityPlayer, int x, int y, int z) {}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if(block != Blocks.furnace && block != Blocks.lit_furnace && block != Blocks.dropper && block != Blocks.hopper && block != Blocks.dispenser && block != Blocks.piston && block != Blocks.sticky_piston) {
|
||||
|
@ -41,11 +42,13 @@ public class ItemWrench extends ItemBase implements IToolConfigurator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldPassSneakingClickToBlock(World world, int x, int y, int z) {
|
||||
@Override
|
||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -29,7 +30,7 @@ import universalelectricity.prefab.tile.TileEntityElectricityStorage;
|
|||
public class TileEntityBatteryBox extends TileEntityElectricityStorage implements IElectricityStorage, ISidedInventory {
|
||||
|
||||
private ItemStack[] containingItems = new ItemStack[2];
|
||||
public final Set playersUsing = new HashSet();
|
||||
public final Set<EntityPlayer> playersUsing = new HashSet();
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -56,14 +57,11 @@ public class TileEntityBatteryBox extends TileEntityElectricityStorage implement
|
|||
|
||||
this.setJoules(this.getJoules() - 5.0E-5D);
|
||||
if(!this.worldObj.isRemote && super.ticks % 3L == 0L) {
|
||||
/*Iterator i$1 = this.playersUsing.iterator();
|
||||
|
||||
while(i$1.hasNext()) {
|
||||
EntityPlayer player1 = (EntityPlayer)i$1.next();
|
||||
|
||||
PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player1);
|
||||
}*/
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
for (EntityPlayer player : this.playersUsing) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(getDescriptionPacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
@ -38,7 +39,7 @@ public class TileEntityCoalGenerator extends TileEntityElectrical implements IIn
|
|||
public IConductor connectedElectricUnit = null;
|
||||
public int itemCookTime = 0;
|
||||
private ItemStack[] containingItems = new ItemStack[1];
|
||||
public final Set playersUsing = new HashSet();
|
||||
public final Set<EntityPlayer> playersUsing = new HashSet();
|
||||
|
||||
|
||||
public boolean canConnect(ForgeDirection direction) {
|
||||
|
@ -90,13 +91,11 @@ public class TileEntityCoalGenerator extends TileEntityElectrical implements IIn
|
|||
}
|
||||
|
||||
if(super.ticks % 3L == 0L) {
|
||||
/*Iterator i$ = this.playersUsing.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
EntityPlayer player = (EntityPlayer)i$.next();
|
||||
PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player);
|
||||
}*/
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
for (EntityPlayer player : this.playersUsing) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(getDescriptionPacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.prevGenerateWatts <= 0.0D && this.generateWatts > 0.0D || this.prevGenerateWatts > 0.0D && this.generateWatts <= 0.0D) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -28,7 +29,7 @@ public class TileEntityElectricFurnace extends TileEntityElectricityRunnable imp
|
|||
public static final int PROCESS_TIME_REQUIRED = 130;
|
||||
public int processTicks = 0;
|
||||
private ItemStack[] containingItems = new ItemStack[3];
|
||||
public final Set playersUsing = new HashSet();
|
||||
public final Set<EntityPlayer> playersUsing = new HashSet();
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
@ -58,13 +59,11 @@ public class TileEntityElectricFurnace extends TileEntityElectricityRunnable imp
|
|||
}
|
||||
|
||||
if(super.ticks % 3L == 0L) {
|
||||
/*Iterator i$ = this.playersUsing.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
EntityPlayer player = (EntityPlayer)i$.next();
|
||||
PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player);
|
||||
}*/
|
||||
|
||||
for (EntityPlayer player : this.playersUsing) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(getDescriptionPacket());
|
||||
}
|
||||
}
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,93 +4,88 @@ package universalelectricity.core.electricity;
|
|||
public class ElectricityDisplay {
|
||||
|
||||
public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces, boolean isShort) {
|
||||
String unitName = unit.name;
|
||||
if(isShort) {
|
||||
unitName = unit.symbol;
|
||||
} else if(value > 1.0D) {
|
||||
unitName = unit.getPlural();
|
||||
}
|
||||
|
||||
return value == 0.0D?value + " " + unitName:(value <= ElectricityDisplay.MeasurementUnit.MILLI.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MICRO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MICRO.getName(isShort) + unitName:(value < 1.0D?roundDecimals(ElectricityDisplay.MeasurementUnit.MILLI.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MILLI.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.MEGA.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MEGA.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MEGA.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.KILO.value?roundDecimals(ElectricityDisplay.MeasurementUnit.KILO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.KILO.getName(isShort) + unitName:roundDecimals(value, decimalPlaces) + " " + unitName))));
|
||||
String unitName = unit.name;
|
||||
if(isShort) {
|
||||
unitName = unit.symbol;
|
||||
} else if(value > 1.0D) {
|
||||
unitName = unit.getPlural();
|
||||
}
|
||||
|
||||
return value == 0.0D?value + " " + unitName:(value <= ElectricityDisplay.MeasurementUnit.MILLI.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MICRO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MICRO.getName(isShort) + unitName:(value < 1.0D?roundDecimals(ElectricityDisplay.MeasurementUnit.MILLI.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MILLI.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.MEGA.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MEGA.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MEGA.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.KILO.value?roundDecimals(ElectricityDisplay.MeasurementUnit.KILO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.KILO.getName(isShort) + unitName:roundDecimals(value, decimalPlaces) + " " + unitName))));
|
||||
}
|
||||
|
||||
public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit) {
|
||||
return getDisplay(value, unit, 2, false);
|
||||
return getDisplay(value, unit, 2, false);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit) {
|
||||
return getDisplay(value, unit, 2, true);
|
||||
return getDisplay(value, unit, 2, true);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) {
|
||||
return getDisplay(value, unit, decimalPlaces, true);
|
||||
return getDisplay(value, unit, decimalPlaces, true);
|
||||
}
|
||||
|
||||
public static String getDisplaySimple(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) {
|
||||
return value > 1.0D?(decimalPlaces < 1?(int)value + " " + unit.getPlural():roundDecimals(value, decimalPlaces) + " " + unit.getPlural()):(decimalPlaces < 1?(int)value + " " + unit.name:roundDecimals(value, decimalPlaces) + " " + unit.name);
|
||||
return value > 1.0D?(decimalPlaces < 1?(int)value + " " + unit.getPlural():roundDecimals(value, decimalPlaces) + " " + unit.getPlural()):(decimalPlaces < 1?(int)value + " " + unit.name:roundDecimals(value, decimalPlaces) + " " + unit.name);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d, int decimalPlaces) {
|
||||
int j = (int)(d * Math.pow(10.0D, (double)decimalPlaces));
|
||||
return (double)j / Math.pow(10.0D, (double)decimalPlaces);
|
||||
int j = (int)(d * Math.pow(10.0D, (double)decimalPlaces));
|
||||
return (double)j / Math.pow(10.0D, (double)decimalPlaces);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d) {
|
||||
return roundDecimals(d, 2);
|
||||
return roundDecimals(d, 2);
|
||||
}
|
||||
|
||||
public static enum ElectricUnit {
|
||||
|
||||
AMPERE("AMPERE", 0, "Amp", "I"),
|
||||
AMP_HOUR("AMP_HOUR", 1, "Amp Hour", "Ah"),
|
||||
VOLTAGE("VOLTAGE", 2, "Volt", "V"),
|
||||
WATT("WATT", 3, "Watt", "W"),
|
||||
WATT_HOUR("WATT_HOUR", 4, "Watt Hour", "Wh"),
|
||||
RESISTANCE("RESISTANCE", 5, "Ohm", "R"),
|
||||
CONDUCTANCE("CONDUCTANCE", 6, "Siemen", "S"),
|
||||
JOULES("JOULES", 7, "Joule", "J");
|
||||
AMPERE("Amp", "I"),
|
||||
AMP_HOUR("Amp Hour", "Ah"),
|
||||
VOLTAGE("Volt", "V"),
|
||||
WATT("Watt", "W"),
|
||||
WATT_HOUR("Watt Hour", "Wh"),
|
||||
RESISTANCE("Ohm", "R"),
|
||||
CONDUCTANCE("Siemen", "S"),
|
||||
JOULES("Joule", "J");
|
||||
public String name;
|
||||
public String symbol;
|
||||
// $FF: synthetic field
|
||||
private static final ElectricityDisplay.ElectricUnit[] $VALUES = new ElectricityDisplay.ElectricUnit[]{AMPERE, AMP_HOUR, VOLTAGE, WATT, WATT_HOUR, RESISTANCE, CONDUCTANCE, JOULES};
|
||||
|
||||
|
||||
private ElectricUnit(String var1, int var2, String name, String symbol) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
private ElectricUnit(String name, String symbol) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getPlural() {
|
||||
return this.name + "s";
|
||||
return this.name + "s";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum MeasurementUnit {
|
||||
|
||||
MICRO("MICRO", 0, "Micro", "mi", 1.0E-6D),
|
||||
MILLI("MILLI", 1, "Milli", "m", 0.001D),
|
||||
KILO("KILO", 2, "Kilo", "k", 1000.0D),
|
||||
MEGA("MEGA", 3, "Mega", "M", 1000000.0D);
|
||||
MICRO("Micro", "mi", 1.0E-6D),
|
||||
MILLI("Milli", "m", 0.001D),
|
||||
KILO("Kilo", "k", 1000.0D),
|
||||
MEGA("Mega", "M", 1000000.0D);
|
||||
public String name;
|
||||
public String symbol;
|
||||
public double value;
|
||||
// $FF: synthetic field
|
||||
private static final ElectricityDisplay.MeasurementUnit[] $VALUES = new ElectricityDisplay.MeasurementUnit[]{MICRO, MILLI, KILO, MEGA};
|
||||
|
||||
|
||||
private MeasurementUnit(String var1, int var2, String name, String symbol, double value) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
this.value = value;
|
||||
private MeasurementUnit(String name, String symbol, double value) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName(boolean isSymbol) {
|
||||
return isSymbol?this.symbol:this.name;
|
||||
return isSymbol?this.symbol:this.name;
|
||||
}
|
||||
|
||||
public double process(double value) {
|
||||
return value / this.value;
|
||||
return value / this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
226
src/main/java/universalelectricity/prefab/flag/CommandFlag.java
Normal file
226
src/main/java/universalelectricity/prefab/flag/CommandFlag.java
Normal file
|
@ -0,0 +1,226 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public class CommandFlag extends CommandBase {
|
||||
|
||||
public static final String[] COMMANDS = new String[]{"list", "setregion", "removeregion", "set"};
|
||||
public String commandName;
|
||||
public ModFlag modFlagData;
|
||||
|
||||
|
||||
public CommandFlag(ModFlag modFlag) {
|
||||
this.commandName = "modflag";
|
||||
this.modFlagData = modFlag;
|
||||
}
|
||||
|
||||
public CommandFlag(ModFlag modFlag, String commandName) {
|
||||
this(modFlag);
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
public String getCommandName() {
|
||||
return this.commandName;
|
||||
}
|
||||
|
||||
public String getCommandUsage(ICommandSender par1ICommandSender) {
|
||||
String returnString = "";
|
||||
String[] arr$ = COMMANDS;
|
||||
int len$ = arr$.length;
|
||||
|
||||
for(int i$ = 0; i$ < len$; ++i$) {
|
||||
String command = arr$[i$];
|
||||
returnString = returnString + "\n/" + this.getCommandName() + " " + command;
|
||||
}
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if(args.length > 0) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer)sender;
|
||||
FlagWorld flagWorld = this.modFlagData.getFlagWorld(entityPlayer.worldObj);
|
||||
String commandName = args[0].toLowerCase();
|
||||
String regionName;
|
||||
String flagName;
|
||||
FlagRegion flagRegion;
|
||||
if(commandName.equalsIgnoreCase("list")) {
|
||||
if(args.length > 1) {
|
||||
regionName = args[1];
|
||||
Iterator flagRegion1;
|
||||
if(regionName.equalsIgnoreCase("all")) {
|
||||
flagName = "";
|
||||
flagRegion1 = this.modFlagData.getFlagWorlds().iterator();
|
||||
|
||||
FlagRegion i$1;
|
||||
while(flagRegion1.hasNext()) {
|
||||
for(Iterator flags1 = ((FlagWorld)flagRegion1.next()).getRegions().iterator(); flags1.hasNext(); flagName = flagName + " " + i$1.name + " (" + i$1.region.min.x + "," + i$1.region.min.z + ")" + ",") {
|
||||
i$1 = (FlagRegion)flags1.next();
|
||||
}
|
||||
}
|
||||
|
||||
if(flagName != "") {
|
||||
flagName = "List of regions in world:\n" + flagName;
|
||||
} else {
|
||||
flagName = "No regions in this world.";
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(flagName));
|
||||
} else {
|
||||
Flag flags2;
|
||||
if(flagWorld.getRegion(regionName) != null) {
|
||||
flagName = "";
|
||||
|
||||
for(flagRegion1 = flagWorld.getRegion(regionName).getFlags().iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + " => " + flags2.value + ",") {
|
||||
flags2 = (Flag)flagRegion1.next();
|
||||
}
|
||||
|
||||
if(flagName != "") {
|
||||
flagName = "List of flags in region " + regionName + ":\n" + flagName;
|
||||
} else {
|
||||
flagName = "No flags in this region.";
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(flagName));
|
||||
} else {
|
||||
flagName = "Region does not exist, but here are existing flags in the position you are standing on:\n";
|
||||
|
||||
for(flagRegion1 = flagWorld.getFlagsInPosition(new Vector3(entityPlayer)).iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + "=>" + flags2.value + ",") {
|
||||
flags2 = (Flag)flagRegion1.next();
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(flagName));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
regionName = "";
|
||||
|
||||
for(Iterator flagName3 = flagWorld.getRegions().iterator(); flagName3.hasNext(); regionName = regionName + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",") {
|
||||
flagRegion = (FlagRegion)flagName3.next();
|
||||
}
|
||||
|
||||
if(regionName != "") {
|
||||
regionName = "List of regions in this dimension:\n" + regionName;
|
||||
} else {
|
||||
regionName = "No regions in this dimension.";
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(regionName));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(commandName.equalsIgnoreCase("setregion")) {
|
||||
if(args.length > 1) {
|
||||
regionName = args[1];
|
||||
if(regionName.equalsIgnoreCase("dimension")) {
|
||||
if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), 1)) {
|
||||
sender.addChatMessage(new ChatComponentText("Created global dimension region setting."));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(args.length <= 2) {
|
||||
throw new WrongUsageException("/" + this.getCommandName() + " addregion <name> <radius>", new Object[0]);
|
||||
}
|
||||
|
||||
boolean flagName1 = false;
|
||||
|
||||
int flagName2;
|
||||
try {
|
||||
flagName2 = Integer.parseInt(args[2]);
|
||||
} catch (Exception var12) {
|
||||
throw new WrongUsageException("Radius not a number!", new Object[0]);
|
||||
}
|
||||
|
||||
if(flagName2 <= 0) {
|
||||
throw new WrongUsageException("Radius has to be greater than zero!", new Object[0]);
|
||||
}
|
||||
|
||||
flagRegion = flagWorld.getRegion(regionName);
|
||||
if(flagRegion == null) {
|
||||
if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), flagName2)) {
|
||||
sender.addChatMessage(new ChatComponentText("Region " + regionName + " added."));
|
||||
}
|
||||
} else {
|
||||
flagRegion.edit(new Vector3(entityPlayer), flagName2);
|
||||
sender.addChatMessage(new ChatComponentText("Region " + regionName + " already exists. Modified region to have a radius of: " + flagName2));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new WrongUsageException("Please specify the region name.", new Object[0]);
|
||||
}
|
||||
|
||||
if(commandName.equalsIgnoreCase("removeregion")) {
|
||||
if(args.length > 1) {
|
||||
regionName = args[1];
|
||||
if(flagWorld.removeRegion(regionName)) {
|
||||
sender.addChatMessage(new ChatComponentText("Region with name " + regionName + " is removed."));
|
||||
return;
|
||||
}
|
||||
|
||||
throw new WrongUsageException("The specified region does not exist in this world.", new Object[0]);
|
||||
}
|
||||
|
||||
throw new WrongUsageException("Please specify the region name.", new Object[0]);
|
||||
}
|
||||
|
||||
if(commandName.equalsIgnoreCase("set")) {
|
||||
if(args.length <= 2) {
|
||||
throw new WrongUsageException("/" + this.getCommandName() + " set <regionName> <flagName> <value>", new Object[0]);
|
||||
}
|
||||
|
||||
regionName = args[1];
|
||||
flagName = args[2];
|
||||
flagRegion = flagWorld.getRegion(regionName);
|
||||
if(flagRegion == null) {
|
||||
throw new WrongUsageException("The specified region \'" + regionName + "\' does not exist.", new Object[0]);
|
||||
}
|
||||
|
||||
String flags;
|
||||
if(FlagRegistry.flags.contains(flagName)) {
|
||||
if(args.length > 3) {
|
||||
flags = args[3];
|
||||
flagRegion.setFlag(flagName, flags);
|
||||
sender.addChatMessage(new ChatComponentText("Flag \'" + flagName + "\' has been set to \'" + flags + "\' in " + regionName + "."));
|
||||
} else {
|
||||
flagRegion.removeFlag(flagName);
|
||||
sender.addChatMessage(new ChatComponentText("Removed flag \'" + flagName + "\'."));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
flags = "Flag does not exist. Existing flags:\n";
|
||||
|
||||
String registeredFlag;
|
||||
for(Iterator i$ = FlagRegistry.flags.iterator(); i$.hasNext(); flags = flags + registeredFlag + ", ") {
|
||||
registeredFlag = (String)i$.next();
|
||||
}
|
||||
|
||||
throw new WrongUsageException(flags, new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
throw new WrongUsageException(this.getCommandUsage(sender), new Object[0]);
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
return args.length == 1?getListOfStringsMatchingLastWord(args, COMMANDS):null;
|
||||
}
|
||||
|
||||
}
|
31
src/main/java/universalelectricity/prefab/flag/Flag.java
Normal file
31
src/main/java/universalelectricity/prefab/flag/Flag.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class Flag extends FlagBase {
|
||||
|
||||
public FlagRegion flagRegion;
|
||||
public String name;
|
||||
public String value;
|
||||
|
||||
|
||||
public Flag(FlagRegion flagRegion) {
|
||||
this.flagRegion = flagRegion;
|
||||
}
|
||||
|
||||
public Flag(FlagRegion flagRegion, String name, String value) {
|
||||
this(flagRegion);
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
this.name = nbt.getString("name");
|
||||
this.value = nbt.getString("value");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setString("name", this.name);
|
||||
nbt.setString("value", this.value);
|
||||
}
|
||||
}
|
23
src/main/java/universalelectricity/prefab/flag/FlagBase.java
Normal file
23
src/main/java/universalelectricity/prefab/flag/FlagBase.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class FlagBase {
|
||||
|
||||
public abstract void readFromNBT(NBTTagCompound var1);
|
||||
|
||||
public abstract void writeToNBT(NBTTagCompound var1);
|
||||
|
||||
public NBTTagCompound getNBT() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
||||
try {
|
||||
this.writeToNBT(nbt);
|
||||
} catch (Exception var3) {
|
||||
System.out.println("Failed to read flag");
|
||||
var3.printStackTrace();
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
130
src/main/java/universalelectricity/prefab/flag/FlagRegion.java
Normal file
130
src/main/java/universalelectricity/prefab/flag/FlagRegion.java
Normal file
|
@ -0,0 +1,130 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.vector.Region3;
|
||||
|
||||
public class FlagRegion extends FlagBase {
|
||||
|
||||
public FlagWorld flagWorld;
|
||||
public String name;
|
||||
public Region3 region;
|
||||
private final List<Flag> flags = new ArrayList();
|
||||
|
||||
|
||||
public FlagRegion(FlagWorld worldFlagData) {
|
||||
this.flagWorld = worldFlagData;
|
||||
}
|
||||
|
||||
public FlagRegion(FlagWorld flagWorld, String name, Region3 region) {
|
||||
this.flagWorld = flagWorld;
|
||||
this.name = name;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
this.name = nbt.getString("name");
|
||||
Vector3 startVector = Vector3.readFromNBT(nbt.getCompoundTag("min"));
|
||||
Vector3 endVector = Vector3.readFromNBT(nbt.getCompoundTag("max"));
|
||||
this.region = new Region3(startVector, endVector);
|
||||
NBTTagList flagList = nbt.getTagList("flags", 10);
|
||||
|
||||
for(int i = 0; i < flagList.tagCount(); ++i) {
|
||||
NBTTagCompound childNode = (NBTTagCompound)flagList.getCompoundTagAt(i);
|
||||
|
||||
Flag e = new Flag(this);
|
||||
e.readFromNBT(childNode);
|
||||
this.flags.add(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setString("name", this.name);
|
||||
nbt.setTag("min", this.region.min.writeToNBT(new NBTTagCompound()));
|
||||
nbt.setTag("max", this.region.max.writeToNBT(new NBTTagCompound()));
|
||||
NBTTagList flagList = new NBTTagList();
|
||||
|
||||
for (Flag flag : this.getFlags()) {
|
||||
flagList.appendTag(flag.getNBT());
|
||||
}
|
||||
|
||||
nbt.setTag("flags", flagList);
|
||||
}
|
||||
|
||||
public boolean containsValue(String flagName, String checkValue, Vector3 position) {
|
||||
Iterator i$ = this.flags.iterator();
|
||||
|
||||
Flag flag;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
flag = (Flag)i$.next();
|
||||
} while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setFlag(String flagName, String value) {
|
||||
this.removeFlag(flagName);
|
||||
return value != null && value != "" && !this.containsFlag(flagName)?this.flags.add(new Flag(this, flagName, value)):false;
|
||||
}
|
||||
|
||||
public boolean containsFlag(String flagName) {
|
||||
Iterator i$ = this.flags.iterator();
|
||||
|
||||
Flag region;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region = (Flag)i$.next();
|
||||
} while(!region.name.equalsIgnoreCase(flagName));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeFlag(String flagName) {
|
||||
Iterator i$ = this.flags.iterator();
|
||||
|
||||
Flag region;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region = (Flag)i$.next();
|
||||
} while(!region.name.equalsIgnoreCase(flagName));
|
||||
|
||||
this.flags.remove(region);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Flag> getFlags() {
|
||||
Iterator<Flag> it = this.flags.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
Flag flag = (Flag)it.next();
|
||||
if(flag == null) {
|
||||
it.remove();
|
||||
} else if(flag.name == null || flag.name == "") {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return this.flags;
|
||||
}
|
||||
|
||||
public void edit(Vector3 position, int radius) {
|
||||
Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius));
|
||||
Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.flagWorld.world.getHeight(), (double)(position.intZ() + radius));
|
||||
this.region = new Region3(minVec, maxVec);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import universalelectricity.prefab.flag.ModFlag;
|
||||
|
||||
public class FlagRegistry {
|
||||
|
||||
public static final String DEFAULT_NAME = "ModFlags";
|
||||
private static final HashMap MOD_FLAGS = new HashMap();
|
||||
public static final List flags = new ArrayList();
|
||||
public static boolean isInitiated = false;
|
||||
|
||||
|
||||
public static void registerModFlag(String name, ModFlag flagData) {
|
||||
MOD_FLAGS.put(name, flagData);
|
||||
}
|
||||
|
||||
public static ModFlag getModFlag(String name) {
|
||||
return (ModFlag)MOD_FLAGS.get(name);
|
||||
}
|
||||
|
||||
public static String registerFlag(String name) {
|
||||
if(!isInitiated) {
|
||||
isInitiated = true;
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
if(!flags.contains(name)) {
|
||||
flags.add(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
164
src/main/java/universalelectricity/prefab/flag/FlagWorld.java
Normal file
164
src/main/java/universalelectricity/prefab/flag/FlagWorld.java
Normal file
|
@ -0,0 +1,164 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.vector.Region3;
|
||||
|
||||
public class FlagWorld extends FlagBase {
|
||||
|
||||
public static final String GLOBAL_REGION = "dimension";
|
||||
public World world;
|
||||
private final List<FlagRegion> regions = new ArrayList();
|
||||
|
||||
|
||||
public FlagWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
for(String key : (Set<String>) nbt.func_150296_c()) {
|
||||
NBTTagCompound childCompound = nbt.getCompoundTag(key);
|
||||
FlagRegion e = new FlagRegion(this);
|
||||
e.readFromNBT(childCompound);
|
||||
this.regions.add(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
Iterator i$ = this.regions.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
FlagRegion region = (FlagRegion)i$.next();
|
||||
|
||||
try {
|
||||
NBTTagCompound e = new NBTTagCompound();
|
||||
region.writeToNBT(e);
|
||||
nbt.setTag(region.name, e);
|
||||
} catch (Exception var5) {
|
||||
System.out.println("Failed to save world flag data: " + region.name);
|
||||
var5.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List getFlagsInPosition(Vector3 position) {
|
||||
ArrayList returnFlags = new ArrayList();
|
||||
Iterator i$ = this.regions.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
FlagRegion flagRegion = (FlagRegion)i$.next();
|
||||
if(flagRegion.region.isIn(position) || flagRegion.name.equalsIgnoreCase("dimension")) {
|
||||
Iterator i$1 = flagRegion.getFlags().iterator();
|
||||
|
||||
while(i$1.hasNext()) {
|
||||
Flag flag = (Flag)i$1.next();
|
||||
returnFlags.add(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnFlags;
|
||||
}
|
||||
|
||||
public List getValues(String flagName, Vector3 position) {
|
||||
ArrayList values = new ArrayList();
|
||||
Iterator i$ = this.getFlagsInPosition(position).iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
Flag flag = (Flag)i$.next();
|
||||
values.add(flag.value);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public boolean containsValue(String flagName, String checkValue, Vector3 position) {
|
||||
Iterator i$ = this.getFlagsInPosition(position).iterator();
|
||||
|
||||
Flag flag;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
flag = (Flag)i$.next();
|
||||
} while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addRegion(String name, Vector3 position, int radius) {
|
||||
Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius));
|
||||
Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.world.getHeight(), (double)(position.intZ() + radius));
|
||||
return this.regions.add(new FlagRegion(this, name, new Region3(minVec, maxVec)));
|
||||
}
|
||||
|
||||
public FlagRegion getRegion(String name) {
|
||||
Iterator i$ = this.regions.iterator();
|
||||
|
||||
FlagRegion region;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
region = (FlagRegion)i$.next();
|
||||
} while(!region.name.equals(name));
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public List getRegions(Vector3 position) {
|
||||
ArrayList returnRegions = new ArrayList();
|
||||
Iterator i$ = this.regions.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
FlagRegion region = (FlagRegion)i$.next();
|
||||
if(region.region.isIn(position)) {
|
||||
returnRegions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
return returnRegions;
|
||||
}
|
||||
|
||||
public boolean removeRegion(String name) {
|
||||
Iterator i$ = this.regions.iterator();
|
||||
|
||||
FlagRegion region;
|
||||
do {
|
||||
if(!i$.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region = (FlagRegion)i$.next();
|
||||
} while(!region.name.equals(name));
|
||||
|
||||
this.regions.remove(region);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<FlagRegion> getRegions() {
|
||||
Iterator it = this.regions.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
FlagRegion region = (FlagRegion)it.next();
|
||||
if(region == null) {
|
||||
it.remove();
|
||||
} else if(region.name == null || region.name == "") {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return this.regions;
|
||||
}
|
||||
}
|
84
src/main/java/universalelectricity/prefab/flag/ModFlag.java
Normal file
84
src/main/java/universalelectricity/prefab/flag/ModFlag.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public class ModFlag extends FlagBase {
|
||||
|
||||
private final List<FlagWorld> flagWorlds = new ArrayList();
|
||||
|
||||
|
||||
public ModFlag(NBTTagCompound nbt) {
|
||||
this.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
if(nbt != null) {
|
||||
for (String key : (Set<String>) nbt.func_150296_c()) {
|
||||
NBTTagCompound dimensionCompound = nbt.getCompoundTag(key);
|
||||
int e = Integer.parseInt(key.replace("dim_", ""));
|
||||
WorldServer world = DimensionManager.getWorld(e);
|
||||
FlagWorld flagWorld = new FlagWorld(world);
|
||||
flagWorld.readFromNBT(dimensionCompound);
|
||||
this.flagWorlds.add(flagWorld);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
if(nbt != null) {
|
||||
Iterator i$ = this.flagWorlds.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
FlagWorld worldData = (FlagWorld)i$.next();
|
||||
|
||||
try {
|
||||
nbt.setTag("dim_" + worldData.world.provider.dimensionId, worldData.getNBT());
|
||||
} catch (Exception var5) {
|
||||
System.out.println("Mod Flag: Failed to save world flag data: " + worldData.world);
|
||||
var5.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FlagWorld getFlagWorld(World world) {
|
||||
FlagWorld worldData = null;
|
||||
if(world != null) {
|
||||
Iterator i$ = this.flagWorlds.iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
FlagWorld data = (FlagWorld)i$.next();
|
||||
if(data.world != null && data.world.provider != null && data.world.provider.dimensionId == world.provider.dimensionId) {
|
||||
worldData = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(worldData == null) {
|
||||
worldData = new FlagWorld(world);
|
||||
this.flagWorlds.add(worldData);
|
||||
}
|
||||
}
|
||||
|
||||
return worldData;
|
||||
}
|
||||
|
||||
public boolean containsValue(World world, String flagName, String checkValue, Vector3 position) {
|
||||
return this.getFlagWorld(world).containsValue(flagName, checkValue, position);
|
||||
}
|
||||
|
||||
public List<FlagWorld> getFlagWorlds() {
|
||||
return this.flagWorlds;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class NBTFileLoader {
|
||||
|
||||
public static boolean saveData(File saveDirectory, String filename, NBTTagCompound data) {
|
||||
try {
|
||||
File e = new File(saveDirectory, filename + "_tmp.dat");
|
||||
File file = new File(saveDirectory, filename + ".dat");
|
||||
CompressedStreamTools.writeCompressed(data, new FileOutputStream(e));
|
||||
if(file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
e.renameTo(file);
|
||||
FMLLog.fine("Saved " + filename + " NBT data file successfully.", new Object[0]);
|
||||
return true;
|
||||
} catch (Exception var5) {
|
||||
System.out.println("Failed to save " + filename + ".dat!");
|
||||
var5.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean saveData(String filename, NBTTagCompound data) {
|
||||
return saveData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data);
|
||||
}
|
||||
|
||||
public static NBTTagCompound loadData(File saveDirectory, String filename) {
|
||||
try {
|
||||
File e = new File(saveDirectory, filename + ".dat");
|
||||
if(e.exists()) {
|
||||
FMLLog.fine("Loaded " + filename + " data.", new Object[0]);
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(e));
|
||||
} else {
|
||||
FMLLog.fine("Created new " + filename + " data.", new Object[0]);
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
System.out.println("Failed to load " + filename + ".dat!");
|
||||
var3.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTTagCompound loadData(String filename) {
|
||||
return loadData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename);
|
||||
}
|
||||
|
||||
public static File getSaveDirectory(String worldName) {
|
||||
File parent = getBaseDirectory();
|
||||
if(FMLCommonHandler.instance().getSide().isClient()) {
|
||||
parent = new File(getBaseDirectory(), "saves" + File.separator);
|
||||
}
|
||||
|
||||
return new File(parent, worldName + File.separator);
|
||||
}
|
||||
|
||||
public static File getBaseDirectory() {
|
||||
if(FMLCommonHandler.instance().getSide().isClient()) {
|
||||
FMLClientHandler.instance().getClient();
|
||||
return Minecraft.getMinecraft().mcDataDir;
|
||||
} else {
|
||||
return new File(".");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,15 @@ public class BlockMulti extends BlockContainer {
|
|||
|
||||
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock) {
|
||||
worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this);
|
||||
((TileEntityMulti)worldObj.getTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
|
||||
TileEntity tile = position.getTileEntity(worldObj);
|
||||
if (tile instanceof TileEntityMulti) {
|
||||
((TileEntityMulti)tile).setMainBlock(mainBlock);
|
||||
} else {
|
||||
TileEntityMulti newTile = (TileEntityMulti)createNewTileEntity(worldObj, 0);
|
||||
worldObj.setTileEntity(position.intX(), position.intY(), position.intZ(), newTile);
|
||||
newTile.setMainBlock(mainBlock);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
Loading…
Reference in a new issue