More work on the syncing issues, should be all fixed :)

This commit is contained in:
modmuss50 2015-05-22 21:15:19 +01:00
parent e930ea2a04
commit 0298621cb9
20 changed files with 67 additions and 89 deletions

View file

@ -6,6 +6,7 @@ import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import techreborn.tiles.TileMachineBase;
import techreborn.util.Inventory;
import techreborn.util.ItemUtils;
@ -81,6 +82,7 @@ public class RecipeCrafter {
public IBaseRecipeType currentRecipe;
public int currentTickTime = 0;
double lastEnergy;
/**
* Call this on the tile tick
@ -98,18 +100,19 @@ public class RecipeCrafter {
if(canGiveInvAll){
currentRecipe = recipe;//Sets the current recipe then syncs
parentTile.needsSync = true;
return;
}
}
}
if(lastEnergy != energy.getEnergyStored()){
parentTile.needsSync = true;
}
} else {
if(!hasAllInputs()){//If it doesn't have all the inputs reset
currentRecipe = null;
currentTickTime = 0;
parentTile.needsSync = true;
return;
}
if (currentTickTime >= currentRecipe.tickTime()) {//If it has reached the recipe tick time
if (currentRecipe != null && currentTickTime >= currentRecipe.tickTime()) {//If it has reached the recipe tick time
boolean canGiveInvAll = true;
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {//Checks to see if it can fit the output
if (!canFitStack(currentRecipe.getOutputs().get(i), outputSlots[i])) {
@ -127,9 +130,12 @@ public class RecipeCrafter {
useAllInputs();//this uses all the inputs
currentRecipe = null;//resets
currentTickTime = 0;
parentTile.needsSync = true;
//Force sync after craft
parentTile.syncWithAll();
parentTile.needsSync = false;
parentTile.ticksSinceLastSync = 0;
}
} else if (currentTickTime < currentRecipe.tickTime()) {
} else if (currentRecipe != null && currentTickTime < currentRecipe.tickTime()) {
if (energy.canUseEnergy(currentRecipe.euPerTick())) {//This checks to see if it can use the power
if(!parentTile.getWorldObj().isRemote){//remove the power on the server side only
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
@ -139,6 +145,7 @@ public class RecipeCrafter {
}
}
}
lastEnergy = energy.getEnergyStored();
}
public boolean hasAllInputs(){

View file

@ -5,6 +5,7 @@ import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
@ -93,7 +94,7 @@ public class BlockMachineBase extends BlockContainer{
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
super.onBlockPlacedBy(world, x, y, z, player, itemstack);
}
public boolean canCreatureSpawn(EnumCreatureType type, World world, int x,
@ -101,5 +102,4 @@ public class BlockMachineBase extends BlockContainer{
{
return false;
}
}

View file

@ -1,6 +1,7 @@
package techreborn.client;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.client.container.ContainerAesu;
import techreborn.client.container.ContainerAlloyFurnace;
@ -43,26 +44,7 @@ import techreborn.client.gui.GuiQuantumTank;
import techreborn.client.gui.GuiRollingMachine;
import techreborn.client.gui.GuiThermalGenerator;
import techreborn.pda.GuiPda;
import techreborn.tiles.TileAesu;
import techreborn.tiles.TileAlloyFurnace;
import techreborn.tiles.TileAlloySmelter;
import techreborn.tiles.TileAssemblingMachine;
import techreborn.tiles.TileBlastFurnace;
import techreborn.tiles.TileCentrifuge;
import techreborn.tiles.TileChemicalReactor;
import techreborn.tiles.TileChunkLoader;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileGrinder;
import techreborn.tiles.TileImplosionCompressor;
import techreborn.tiles.TileIndustrialElectrolyzer;
import techreborn.tiles.TileIndustrialSawmill;
import techreborn.tiles.TileLathe;
import techreborn.tiles.TileMatterFabricator;
import techreborn.tiles.TilePlateCuttingMachine;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileRollingMachine;
import techreborn.tiles.TileThermalGenerator;
import techreborn.tiles.*;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler {
@ -95,6 +77,10 @@ public class GuiHandler implements IGuiHandler {
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z)
{
if(world.getTileEntity(x, y, z) instanceof TileMachineBase){
((TileMachineBase) world.getTileEntity(x, y, z)).syncWithAll();
}
if (ID == thermalGeneratorID)
{
return new ContainerThermalGenerator(

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileAlloySmelter extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileAssemblingMachine extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -14,6 +11,8 @@ import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileCentrifuge extends TileMachineBase implements IWrenchable, IEnergyTile{
public int tickTime;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileChemicalReactor extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -12,12 +12,7 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.*;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.FluidUtils;

View file

@ -7,11 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.*;
import techreborn.api.recipe.RecipeCrafter;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSource;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
@ -13,6 +10,8 @@ import net.minecraft.nbt.NBTTagCompound;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import java.util.List;
public class TileHeatGenerator extends TileMachineBase implements IWrenchable, IEnergyTile {
public BasicSource energy;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileImplosionCompressor extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;
@ -106,4 +105,15 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
}
}
@Override
public void invalidate()
{
energy.invalidate();
}
@Override
public void onChunkUnload()
{
energy.onChunkUnload();
}
}

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileIndustrialElectrolyzer extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileIndustrialSawmill extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TileLathe extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -1,15 +1,15 @@
package techreborn.tiles;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import techreborn.packets.PacketHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
public class TileMachineBase extends TileEntity {
@ -19,11 +19,9 @@ public class TileMachineBase extends TileEntity {
@Override
public void updateEntity() {
super.updateEntity();
//Force a sync evey 30 seconds
if(needsSync && ticksSinceLastSync >= 10 || ticksSinceLastSync == 600){
//Force a sync evey 10 seconds
if(needsSync && !worldObj.isRemote){
syncWithAll();
needsSync = false;
ticksSinceLastSync = 0;
}
ticksSinceLastSync ++;
}
@ -40,6 +38,8 @@ public class TileMachineBase extends TileEntity {
} else {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
needsSync = false;
ticksSinceLastSync = 0;
}
public Packet getDescriptionPacket() {

View file

@ -1,9 +1,9 @@
package techreborn.tiles;
import techreborn.multiblocks.MultiBlockCasing;
import erogenousbeef.coreTR.multiblock.MultiblockControllerBase;
import erogenousbeef.coreTR.multiblock.MultiblockValidationException;
import erogenousbeef.coreTR.multiblock.rectangular.RectangularMultiblockTileEntityBase;
import techreborn.multiblocks.MultiBlockCasing;
public class TileMachineCasing extends RectangularMultiblockTileEntityBase {

View file

@ -3,9 +3,6 @@ package techreborn.tiles;
import ic2.api.energy.prefab.BasicSink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -13,6 +10,8 @@ import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import java.util.List;
public class TilePlateCuttingMachine extends TileMachineBase implements IWrenchable, IEnergyTile {
public int tickTime;

View file

@ -1,9 +1,6 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -15,6 +12,8 @@ import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import techreborn.util.ItemUtils;
import java.util.List;
public class TileQuantumChest extends TileMachineBase implements IInventory,
IWrenchable {

View file

@ -1,9 +1,6 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -21,6 +18,8 @@ import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;
import java.util.List;
public class TileQuantumTank extends TileMachineBase implements IFluidHandler,
IInventory, IWrenchable {

View file

@ -12,12 +12,7 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.*;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.FluidUtils;