Fixes
This commit is contained in:
@@ -66,6 +66,8 @@ public class StorageNetwork {
|
|||||||
private boolean couldRun;
|
private boolean couldRun;
|
||||||
private long lastEnergyUpdate;
|
private long lastEnergyUpdate;
|
||||||
|
|
||||||
|
private int ticks;
|
||||||
|
|
||||||
private EnumControllerType type;
|
private EnumControllerType type;
|
||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
@@ -91,6 +93,10 @@ public class StorageNetwork {
|
|||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getEnergyUsage() {
|
||||||
|
return energyUsage;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockPos getPos() {
|
public BlockPos getPos() {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@@ -103,7 +109,7 @@ public class StorageNetwork {
|
|||||||
return energy.getEnergyStored() > 0 && energy.getEnergyStored() >= energyUsage && redstoneMode.isEnabled(world, pos);
|
return energy.getEnergyStored() > 0 && energy.getEnergyStored() >= energyUsage && redstoneMode.isEnabled(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(int ticks) {
|
public void update() {
|
||||||
for (TileMachine machine : machinesToAdd) {
|
for (TileMachine machine : machinesToAdd) {
|
||||||
if (!machines.contains(machine)) {
|
if (!machines.contains(machine)) {
|
||||||
machines.add(machine);
|
machines.add(machine);
|
||||||
@@ -149,8 +155,6 @@ public class StorageNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!machines.isEmpty()) {
|
} else if (!machines.isEmpty()) {
|
||||||
// Machine list should NOT be empty to trigger a disconnect
|
|
||||||
// We need to sync machines again to reset energy usage etc
|
|
||||||
disconnectAll();
|
disconnectAll();
|
||||||
syncMachines();
|
syncMachines();
|
||||||
}
|
}
|
||||||
@@ -182,6 +186,8 @@ public class StorageNetwork {
|
|||||||
RefinedStorageUtils.updateBlock(world, pos);
|
RefinedStorageUtils.updateBlock(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TileMachine> getMachines() {
|
public List<TileMachine> getMachines() {
|
||||||
|
|||||||
13
src/main/java/refinedstorage/api/storagenet/StorageNetworkTickHandler.java
Executable file
13
src/main/java/refinedstorage/api/storagenet/StorageNetworkTickHandler.java
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
package refinedstorage.api.storagenet;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
|
|
||||||
|
public class StorageNetworkTickHandler {
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onServerTick(TickEvent.ServerTickEvent e) {
|
||||||
|
for (StorageNetwork network : StorageNetworkRegistry.NETWORKS.values()) {
|
||||||
|
network.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,8 +64,10 @@ public class BlockController extends BlockBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||||
|
TileController controller = (TileController) world.getTileEntity(pos);
|
||||||
|
|
||||||
return super.getActualState(state, world, pos)
|
return super.getActualState(state, world, pos)
|
||||||
.withProperty(ENERGY, ((TileController) world.getTileEntity(pos)).getEnergyScaled(8));
|
.withProperty(ENERGY, (int) Math.ceil((float) controller.getEnergy() / (float) StorageNetwork.ENERGY_CAPACITY * 8f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,8 +91,6 @@ public class BlockController extends BlockBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
|
||||||
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
|
||||||
|
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
StorageNetwork network = new StorageNetwork(world, pos, (EnumControllerType) state.getValue(TYPE));
|
StorageNetwork network = new StorageNetwork(world, pos, (EnumControllerType) state.getValue(TYPE));
|
||||||
|
|
||||||
@@ -104,6 +104,8 @@ public class BlockController extends BlockBase {
|
|||||||
|
|
||||||
((TileController) world.getTileEntity(pos)).setNetwork(network);
|
((TileController) world.getTileEntity(pos)).setNetwork(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ import net.minecraft.block.properties.IProperty;
|
|||||||
import net.minecraft.block.properties.PropertyBool;
|
import net.minecraft.block.properties.PropertyBool;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.tile.TileMachine;
|
import refinedstorage.tile.TileMachine;
|
||||||
|
import refinedstorage.tile.controller.ControllerSearcher;
|
||||||
|
import refinedstorage.tile.controller.TileController;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public abstract class BlockMachine extends BlockBase {
|
public abstract class BlockMachine extends BlockBase {
|
||||||
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
|
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
|
||||||
@@ -36,6 +42,19 @@ public abstract class BlockMachine extends BlockBase {
|
|||||||
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||||
|
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
TileController controller = ControllerSearcher.search(world, pos, new HashSet<String>());
|
||||||
|
|
||||||
|
if (controller != null) {
|
||||||
|
((TileMachine) world.getTileEntity(pos)).onConnected(world, controller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package refinedstorage.gui;
|
|||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
import refinedstorage.api.storagenet.StorageNetwork;
|
||||||
import refinedstorage.container.ContainerController;
|
import refinedstorage.container.ContainerController;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.tile.controller.ClientMachine;
|
import refinedstorage.tile.controller.ClientMachine;
|
||||||
@@ -45,7 +46,7 @@ public class GuiController extends GuiBase {
|
|||||||
|
|
||||||
drawTexture(x, y, 0, 0, width, height);
|
drawTexture(x, y, 0, 0, width, height);
|
||||||
|
|
||||||
int barHeightNew = (int) ((float) controller.getEnergyStored(null) / (float) controller.getMaxEnergyStored(null) * (float) barHeight);
|
int barHeightNew = (int) ((float) controller.getEnergy() / (float) StorageNetwork.ENERGY_CAPACITY * (float) barHeight);
|
||||||
|
|
||||||
drawTexture(x + barX, y + barY + barHeight - barHeightNew, 178, barHeight - barHeightNew, barWidth, barHeightNew);
|
drawTexture(x + barX, y + barY + barHeight - barHeightNew, 178, barHeight - barHeightNew, barWidth, barHeightNew);
|
||||||
}
|
}
|
||||||
@@ -102,7 +103,7 @@ public class GuiController extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY)) {
|
if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY)) {
|
||||||
drawTooltip(mouseX, mouseY, t("misc.refinedstorage:energy_usage", controller.getEnergyUsage()) + "\n" + t("misc.refinedstorage:energy_stored", controller.getEnergyStored(null), controller.getMaxEnergyStored(null)));
|
drawTooltip(mouseX, mouseY, t("misc.refinedstorage:energy_usage", controller.getEnergyUsage()) + "\n" + t("misc.refinedstorage:energy_stored", controller.getEnergy(), StorageNetwork.ENERGY_CAPACITY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.init.Blocks;
|
|||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
@@ -19,6 +20,7 @@ import refinedstorage.RefinedStorageItems;
|
|||||||
import refinedstorage.api.solderer.SoldererRecipeBasic;
|
import refinedstorage.api.solderer.SoldererRecipeBasic;
|
||||||
import refinedstorage.api.solderer.SoldererRegistry;
|
import refinedstorage.api.solderer.SoldererRegistry;
|
||||||
import refinedstorage.api.storage.NBTStorage;
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
|
import refinedstorage.api.storagenet.StorageNetworkTickHandler;
|
||||||
import refinedstorage.block.BlockBase;
|
import refinedstorage.block.BlockBase;
|
||||||
import refinedstorage.block.EnumControllerType;
|
import refinedstorage.block.EnumControllerType;
|
||||||
import refinedstorage.block.EnumGridType;
|
import refinedstorage.block.EnumGridType;
|
||||||
@@ -483,6 +485,7 @@ public class CommonProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(FMLInitializationEvent e) {
|
public void init(FMLInitializationEvent e) {
|
||||||
|
MinecraftForge.EVENT_BUS.register(new StorageNetworkTickHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postInit(FMLPostInitializationEvent e) {
|
public void postInit(FMLPostInitializationEvent e) {
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ public abstract class TileMachine extends TileBase implements ISynchronizedConta
|
|||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (ticks == 0) {
|
if (ticks == 0) {
|
||||||
block = worldObj.getBlockState(pos).getBlock();
|
block = worldObj.getBlockState(pos).getBlock();
|
||||||
|
|
||||||
searchController(worldObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasConnected != isActive() && canSendConnectivityData()) {
|
if (wasConnected != isActive() && canSendConnectivityData()) {
|
||||||
|
|||||||
@@ -63,7 +63,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyScaled(int i) {
|
public int getEnergyScaled(int i) {
|
||||||
return (int) ((float) network.getEnergy().getEnergyStored() / (float) network.getEnergy().getMaxEnergyStored() * (float) i);
|
float stored = worldObj.isRemote ? energy : network.getEnergy().getEnergyStored();
|
||||||
|
float max = StorageNetwork.ENERGY_CAPACITY;
|
||||||
|
|
||||||
|
return (int) (stored / max * (float) i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,7 +81,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RedstoneMode getRedstoneMode() {
|
public RedstoneMode getRedstoneMode() {
|
||||||
return network.getRedstoneMode();
|
return worldObj.isRemote ? redstoneMode : network.getRedstoneMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,7 +113,6 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
public void readContainerData(ByteBuf buf) {
|
public void readContainerData(ByteBuf buf) {
|
||||||
this.energy = buf.readInt();
|
this.energy = buf.readInt();
|
||||||
this.energyUsage = buf.readInt();
|
this.energyUsage = buf.readInt();
|
||||||
|
|
||||||
this.redstoneMode = RedstoneMode.getById(buf.readInt());
|
this.redstoneMode = RedstoneMode.getById(buf.readInt());
|
||||||
|
|
||||||
List<ClientMachine> machines = new ArrayList<ClientMachine>();
|
List<ClientMachine> machines = new ArrayList<ClientMachine>();
|
||||||
@@ -131,10 +133,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeContainerData(ByteBuf buf) {
|
public void writeContainerData(ByteBuf buf) {
|
||||||
buf.writeInt(getEnergyStored(null));
|
buf.writeInt(network.getEnergy().getEnergyStored());
|
||||||
buf.writeInt(energyUsage);
|
buf.writeInt(network.getEnergyUsage());
|
||||||
|
|
||||||
buf.writeInt(redstoneMode.id);
|
buf.writeInt(network.getRedstoneMode().id);
|
||||||
|
|
||||||
List<ClientMachine> m = new ArrayList<ClientMachine>();
|
List<ClientMachine> m = new ArrayList<ClientMachine>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user