Recoded idsu, closes #81

This commit is contained in:
modmuss50 2015-07-26 16:01:27 +01:00
parent f433aa706a
commit 5927eaca4c
11 changed files with 68 additions and 224 deletions

View file

@ -66,9 +66,6 @@ public class BlockIDSU extends BlockMachineBase {
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
Core.packetPipeline.sendTo(IDSUManager.INSTANCE.getPacket(world), (EntityPlayerMP) player);
}
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.idsuID, world, x, y,
z);
@ -80,7 +77,8 @@ public class BlockIDSU extends BlockMachineBase {
super.onBlockPlacedBy(world, x, y, z, player, itemstack);
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileIDSU){
((TileIDSU) tile).setFacing((short) world.getBlockMetadata(x, y, z));
}
((TileIDSU) tile).ownerUdid = player.getUniqueID().toString();
System.out.println(((TileIDSU) tile).ownerUdid);
}
}
}

View file

@ -58,9 +58,6 @@ public class ContainerIDSU extends TechRebornContainer {
if (this.euChange != tile.getEuChange() && tile.getEuChange() != -1) {
icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
}
if (this.channel != tile.channelID) {
icrafting.sendProgressBarUpdate(this, 3, tile.channelID);
}
}
}
@ -70,7 +67,6 @@ public class ContainerIDSU extends TechRebornContainer {
crafting.sendProgressBarUpdate(this, 0, tile.output);
crafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
crafting.sendProgressBarUpdate(this, 3, tile.channelID);
}
@SideOnly(Side.CLIENT)

View file

@ -34,11 +34,8 @@ public class TechRebornDevCommand extends CommandBase {
sender.addChatMessage(new ChatComponentText("You need to use arguments, see /trdev help"));
} else if ("help".equals(args[0])) {
sender.addChatMessage(new ChatComponentText("recipes - Shows size of the recipe array"));
sender.addChatMessage(new ChatComponentText("idsu - Resyncs the idsu server instance to the senders client"));
} else if ("recipes".equals(args[0])) {
sender.addChatMessage(new ChatComponentText(RecipeHandler.recipeList.size() + " recipes loaded"));
} else if ("idsu".equals(args[0])){
Core.packetPipeline.sendTo(IDSUManager.INSTANCE.getPacket(sender.getEntityWorld()), (EntityPlayerMP) sender);
}
}
}

View file

@ -66,6 +66,6 @@ public class PacketIdsu extends AbstractPacket {
@Override
public void handleServerSide(EntityPlayer player) {
idsu = (TileIDSU) player.getEntityWorld().getTileEntity(x, y, z);
idsu.handleGuiInputFromClient(buttonID, channel, player, newName);
idsu.handleGuiInputFromClient(buttonID);
}
}

View file

@ -122,7 +122,6 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
private void registerPackets() {
registerPacket(PacketIdsu.class);
registerPacket(PacketSendIDSUManager.class);
}
// Method to call from FMLPostInitializationEvent

View file

@ -1,71 +0,0 @@
package techreborn.packets;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
import techreborn.client.gui.GuiIDSU;
import techreborn.cofhLib.gui.element.listbox.ListBoxElementText;
import techreborn.tiles.idsu.ClientSideIDSUManager;
import techreborn.tiles.idsu.IDSUManager;
import java.io.IOException;
public class PacketSendIDSUManager extends AbstractPacket {
String json;
public PacketSendIDSUManager() {
}
public PacketSendIDSUManager(String json) {
this.json = json;
}
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf out) {
PacketBuffer buffer = new PacketBuffer(out);
try {
buffer.writeStringToBuffer(json);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf in) {
PacketBuffer buffer = new PacketBuffer(in);
try {
json = buffer.readStringFromBuffer(9999999);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void handleClientSide(EntityPlayer player) {
ClientSideIDSUManager.CLIENT.loadFromString(json, player.worldObj);
if(player.worldObj != null){
GuiIDSU.listBox._elements.clear();
for(World world : ClientSideIDSUManager.CLIENT.worldData.keySet()){
IDSUManager.IDSUWorldSaveData saveData = ClientSideIDSUManager.CLIENT.getWorldDataFormWorld(world);
for(Integer id : saveData.idsuValues.keySet()){
IDSUManager.IDSUValueSaveData valueSaveData = saveData.idsuValues.get(id);
System.out.println("added " + valueSaveData.name + " - " + id);
if(!valueSaveData.name.isEmpty()){
GuiIDSU.listBox._elements.add(new ListBoxElementText(valueSaveData.name + " - " + id));
} else {
GuiIDSU.listBox._elements.add(new ListBoxElementText(id.toString()));
}
}
}
}
}
@Override
public void handleServerSide(EntityPlayer player) {
}
}

View file

@ -99,7 +99,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
@Strippable("mod:IC2")
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
energy += amount;
setEnergy(getEnergy() + amount);
return 0;
}
@ -159,7 +159,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
int energyReceived = Math.min(getMaxEnergyStored(ForgeDirection.UNKNOWN) - getEnergyStored(ForgeDirection.UNKNOWN), Math.min((int)this.getMaxInput() * ConfigTechReborn.euPerRF, maxReceive));
if (!simulate) {
energy += energyReceived;
setEnergy(getEnergy() + energyReceived);
}
return energyReceived / ConfigTechReborn.euPerRF;
}
@ -189,7 +189,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
int energyExtracted = Math.min(getEnergyStored(ForgeDirection.UNKNOWN), Math.min(maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
setEnergy(energy - energyExtracted);
}
return energyExtracted / ConfigTechReborn.euPerRF;
}
@ -206,10 +206,10 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
public void setEnergy(double energy) {
this.energy = energy;
if (this.energy > getMaxPower()) {
this.energy = getMaxPower();
if (this.getEnergy() > getMaxPower()) {
this.setEnergy(getMaxPower());
} else if (this.energy < 0) {
this.energy = 0;
this.setEnergy(0);
}
}
@ -223,7 +223,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
double energyReceived = Math.min(getMaxPower() - energy, Math.min(this.getMaxPower(), energy));
if (!simulate) {
this.energy += energyReceived;
setEnergy(energy + energyReceived);
}
return energyReceived;
}
@ -243,7 +243,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
double energyExtracted = Math.min(energy, Math.min(this.getMaxOutput(), energy));
if (!simulate) {
this.energy -= energyExtracted;
setEnergy(energy - energyExtracted);
}
return energyExtracted;
}

View file

@ -5,7 +5,6 @@ import net.minecraftforge.common.MinecraftForge;
import techreborn.client.IconSupplier;
import techreborn.client.hud.ChargeHud;
import techreborn.client.keybindings.KeyBindings;
import techreborn.tiles.idsu.ClientSideIDSUManager;
public class ClientProxy extends CommonProxy {
@ -16,6 +15,5 @@ public class ClientProxy extends CommonProxy {
MinecraftForge.EVENT_BUS.register(new IconSupplier());
MinecraftForge.EVENT_BUS.register(new ChargeHud());
ClientRegistry.registerKeyBinding(KeyBindings.config);
MinecraftForge.EVENT_BUS.register(new ClientSideIDSUManager());
}
}

View file

@ -1,19 +0,0 @@
package techreborn.tiles.idsu;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.event.world.WorldEvent;
@SideOnly(Side.CLIENT)
public class ClientSideIDSUManager {
public static IDSUManager CLIENT = new IDSUManager();
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event) {
CLIENT = new IDSUManager();
}
}

View file

@ -8,7 +8,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.world.World;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraftforge.event.world.WorldEvent;
import techreborn.packets.PacketSendIDSUManager;
import java.io.*;
import java.lang.reflect.Type;
@ -57,7 +56,7 @@ public class IDSUManager {
worldData.clear();
}
public IDSUValueSaveData getSaveDataForWorld(World world, int channel) {
public IDSUValueSaveData getSaveDataForWorld(World world, String channel) {
if (worldData.containsKey(world)) {
return worldData.get(world).getSaves(channel);
} else {
@ -80,14 +79,6 @@ public class IDSUManager {
}
}
public PacketSendIDSUManager getPacket(World world) {
Gson gson = new Gson();
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
if (getWorldDataFormWorld(world).idsuValues.isEmpty()) {
json = "EMPTY";
}
return new PacketSendIDSUManager(json);
}
public void loadFromString(String json, World world) {
if (json.equals("EMPTY")) {
@ -110,7 +101,7 @@ public class IDSUManager {
public class IDSUWorldSaveData {
public TreeMap<Integer, IDSUValueSaveData> idsuValues = new TreeMap<Integer, IDSUValueSaveData>();
public TreeMap<String, IDSUValueSaveData> idsuValues = new TreeMap<String, IDSUValueSaveData>();
public World world;
@ -127,12 +118,12 @@ public class IDSUManager {
file = new File(folder, savename);
}
public IDSUValueSaveData getSaves(int i) {
if (idsuValues.containsKey(i)) {
return idsuValues.get(i);
public IDSUValueSaveData getSaves(String udid) {
if (idsuValues.containsKey(udid)) {
return idsuValues.get(udid);
} else {
IDSUValueSaveData data = new IDSUValueSaveData();
idsuValues.put(i, data);
idsuValues.put(udid, data);
return data;
}
}

View file

@ -9,54 +9,56 @@ import net.minecraftforge.common.util.ForgeDirection;
import techreborn.Core;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.lib.Functions;
import techreborn.powerSystem.TilePowerAcceptor;
public class TileIDSU extends TilePowerAcceptor {
public int channelID = 0;
public void handleGuiInputFromClient(int buttonID, int channel, EntityPlayer player, String name) {
if (buttonID == 4) {
channelID = channel;
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel).name = name;
IDSUManager.INSTANCE.getWorldDataFormWorld(worldObj).save();
if (worldObj.isRemote) {
Core.packetPipeline.sendTo(IDSUManager.INSTANCE.getPacket(worldObj), (EntityPlayerMP) player);
}
}
}
public String ownerUdid;
@Override
public double getEnergy() {
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channelID).storedPower;
}
public void setEnergy(double energy) {
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channelID).storedPower = energy;
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
}
@Override
public void setEnergy(double energy) {
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
}
@Override
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public double getMaxPower() {
return 0;
return 1000000000;
}
@Override
public boolean canAcceptEnergy(ForgeDirection direction) {
return false;
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != Functions.getIntDirFromDirection(direction);
}
@Override
public boolean canProvideEnergy(ForgeDirection direction) {
return false;
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == Functions.getIntDirFromDirection(direction);
}
@Override
public double getMaxOutput() {
return 0;
return output;
}
@Override
public double getMaxInput() {
return 0;
return maxStorage;
}
public int tier;
@ -88,12 +90,12 @@ public class TileIDSU extends TilePowerAcceptor {
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.channelID = nbttagcompound.getInteger("channel");
this.ownerUdid = nbttagcompound.getString("ownerUdid");
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("channel", this.channelID);
nbttagcompound.setString("ownerUdid", this.ownerUdid);
}
public void updateEntity() {
@ -105,13 +107,13 @@ public class TileIDSU extends TilePowerAcceptor {
} else {
ticks++;
euChange += getStored() - euLastTick;
if (euLastTick == getStored()) {
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
euLastTick = getStored();
euLastTick = getEnergy();
boolean needsInvUpdate = false;
@ -122,50 +124,10 @@ public class TileIDSU extends TilePowerAcceptor {
}
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
return false;
}
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
return false;
}
public void drawEnergy(double amount) {
setEnergy(getEnergy() - amount);
}
public double getDemandedEnergy() {
return (double) this.maxStorage - this.getEnergy();
}
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
if (this.getEnergy() >= (double) this.maxStorage) {
return amount;
} else {
setEnergy(this.getEnergy() + amount);
return 0.0D;
}
}
public int getSourceTier() {
return this.tier;
}
public int getSinkTier() {
return this.tier;
}
public void onGuiClosed(EntityPlayer entityPlayer) {
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
public void setFacing(short facing) {
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
NBTTagCompound tileEntity = new NBTTagCompound();
@ -176,34 +138,6 @@ public class TileIDSU extends TilePowerAcceptor {
return dropStack;
}
public int getStored() {
return (int) this.getEnergy();
}
public int getCapacity() {
return (int) this.maxStorage;
}
public int getOutput() {
return this.output;
}
public double getOutputEnergyUnitsPerTick() {
return (double) this.output;
}
public void setStored(int energy1) {
setEnergy(energy1);
}
public int addEnergy(int amount) {
setEnergy(getEnergy() + amount);
return amount;
}
public boolean isTeleporterCompatible(ForgeDirection side) {
return true;
}
public double getEuChange() {
if (euChange == -1) {
@ -211,4 +145,25 @@ public class TileIDSU extends TilePowerAcceptor {
}
return (euChange / ticks);
}
public void handleGuiInputFromClient(int id){
if(id == 0){
output += 256;
}
if(id == 1){
output += 64;
}
if(id == 2){
output -= 64;
}
if(id == 3){
output -= 256;
}
if(output > 4096){
output = 4096;
}
if(output <= -1){
output = 0;
}
}
}