Moved over to the vanilla packet system.
This commit is contained in:
parent
3b56d7c1e1
commit
c5e73c6fc3
5 changed files with 74 additions and 19 deletions
|
@ -80,12 +80,16 @@ public class RecipeCrafter {
|
||||||
|
|
||||||
public IBaseRecipeType currentRecipe;
|
public IBaseRecipeType currentRecipe;
|
||||||
public int currentTickTime = 0;
|
public int currentTickTime = 0;
|
||||||
|
public int currentNeededTicks = 0;
|
||||||
double lastEnergy;
|
double lastEnergy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this on the tile tick
|
* Call this on the tile tick
|
||||||
*/
|
*/
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
|
if(parentTile.getWorldObj().isRemote){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (currentRecipe == null) {//It will now look for new recipes.
|
if (currentRecipe == null) {//It will now look for new recipes.
|
||||||
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
||||||
if (recipe.canCraft(parentTile) && hasAllInputs(recipe)) {//This checks to see if it has all of the inputs
|
if (recipe.canCraft(parentTile) && hasAllInputs(recipe)) {//This checks to see if it has all of the inputs
|
||||||
|
@ -97,18 +101,14 @@ public class RecipeCrafter {
|
||||||
}
|
}
|
||||||
if (canGiveInvAll) {
|
if (canGiveInvAll) {
|
||||||
currentRecipe = recipe;//Sets the current recipe then syncs
|
currentRecipe = recipe;//Sets the current recipe then syncs
|
||||||
parentTile.needsSync = true;
|
this.currentNeededTicks = currentRecipe.tickTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastEnergy != energy.getEnergyStored()) {
|
|
||||||
parentTile.needsSync = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!hasAllInputs()) {//If it doesn't have all the inputs reset
|
if (!hasAllInputs()) {//If it doesn't have all the inputs reset
|
||||||
currentRecipe = null;
|
currentRecipe = null;
|
||||||
currentTickTime = 0;
|
currentTickTime = 0;
|
||||||
parentTile.needsSync = true;
|
|
||||||
}
|
}
|
||||||
if (currentRecipe != null && 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;
|
boolean canGiveInvAll = true;
|
||||||
|
@ -130,8 +130,6 @@ public class RecipeCrafter {
|
||||||
currentTickTime = 0;
|
currentTickTime = 0;
|
||||||
//Force sync after craft
|
//Force sync after craft
|
||||||
parentTile.syncWithAll();
|
parentTile.syncWithAll();
|
||||||
parentTile.needsSync = false;
|
|
||||||
parentTile.ticksSinceLastSync = 0;
|
|
||||||
}
|
}
|
||||||
} else if (currentRecipe != null && 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 (energy.canUseEnergy(currentRecipe.euPerTick())) {//This checks to see if it can use the power
|
||||||
|
@ -139,11 +137,9 @@ public class RecipeCrafter {
|
||||||
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
|
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
|
||||||
}
|
}
|
||||||
currentTickTime++;//increase the ticktime
|
currentTickTime++;//increase the ticktime
|
||||||
parentTile.needsSync = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastEnergy = energy.getEnergyStored();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAllInputs() {
|
public boolean hasAllInputs() {
|
||||||
|
|
|
@ -77,10 +77,6 @@ public class GuiHandler implements IGuiHandler {
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
|
||||||
int x, int y, int z)
|
int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(world.getTileEntity(x, y, z) instanceof TileMachineBase){
|
|
||||||
((TileMachineBase) world.getTileEntity(x, y, z)).syncWithAll();
|
|
||||||
}
|
|
||||||
if (ID == thermalGeneratorID)
|
if (ID == thermalGeneratorID)
|
||||||
{
|
{
|
||||||
return new ContainerThermalGenerator(
|
return new ContainerThermalGenerator(
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package techreborn.client.container;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import net.minecraft.inventory.ICrafting;
|
||||||
|
import techreborn.api.recipe.RecipeCrafter;
|
||||||
|
|
||||||
|
public abstract class ContainerCrafting extends TechRebornContainer {
|
||||||
|
|
||||||
|
RecipeCrafter crafter;
|
||||||
|
|
||||||
|
public int currentTickTime = 0;
|
||||||
|
public int currentNeededTicks = 0;
|
||||||
|
public int energy;
|
||||||
|
|
||||||
|
public ContainerCrafting(RecipeCrafter crafter) {
|
||||||
|
this.crafter = crafter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detectAndSendChanges() {
|
||||||
|
super.detectAndSendChanges();
|
||||||
|
for (int i = 0; i < this.crafters.size(); i++) {
|
||||||
|
ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||||
|
if(this.currentTickTime != crafter.currentTickTime){
|
||||||
|
icrafting.sendProgressBarUpdate(this, 0, crafter.currentTickTime);
|
||||||
|
}
|
||||||
|
if(this.currentNeededTicks != crafter.currentNeededTicks){
|
||||||
|
icrafting.sendProgressBarUpdate(this, 1, crafter.currentNeededTicks);
|
||||||
|
}
|
||||||
|
if(this.energy != (int)crafter.energy.getEnergyStored()){
|
||||||
|
icrafting.sendProgressBarUpdate(this, 2, (int)crafter.energy.getEnergyStored());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCraftingToCrafters(ICrafting crafting) {
|
||||||
|
super.addCraftingToCrafters(crafting);
|
||||||
|
crafting.sendProgressBarUpdate(this, 0, crafter.currentTickTime);
|
||||||
|
crafting.sendProgressBarUpdate(this, 1, crafter.currentNeededTicks);
|
||||||
|
crafting.sendProgressBarUpdate(this, 2, (int)crafter.energy.getEnergyStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
public void updateProgressBar(int id, int value) {
|
||||||
|
if(id == 0){
|
||||||
|
this.currentTickTime = value;
|
||||||
|
} else if(id == 1){
|
||||||
|
this.currentNeededTicks = value;
|
||||||
|
} else if(id == 2){
|
||||||
|
this.energy = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import net.minecraft.inventory.Slot;
|
||||||
import techreborn.client.SlotOutput;
|
import techreborn.client.SlotOutput;
|
||||||
import techreborn.tiles.TileImplosionCompressor;
|
import techreborn.tiles.TileImplosionCompressor;
|
||||||
|
|
||||||
public class ContainerImplosionCompressor extends TechRebornContainer{
|
public class ContainerImplosionCompressor extends ContainerCrafting{
|
||||||
|
|
||||||
EntityPlayer player;
|
EntityPlayer player;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ public class ContainerImplosionCompressor extends TechRebornContainer{
|
||||||
public ContainerImplosionCompressor(TileImplosionCompressor tilecompressor,
|
public ContainerImplosionCompressor(TileImplosionCompressor tilecompressor,
|
||||||
EntityPlayer player)
|
EntityPlayer player)
|
||||||
{
|
{
|
||||||
|
super(tilecompressor.crafter);
|
||||||
tile = tilecompressor;
|
tile = tilecompressor;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
import techreborn.client.container.ContainerCrafting;
|
||||||
import techreborn.client.container.ContainerImplosionCompressor;
|
import techreborn.client.container.ContainerImplosionCompressor;
|
||||||
import techreborn.tiles.TileImplosionCompressor;
|
import techreborn.tiles.TileImplosionCompressor;
|
||||||
|
|
||||||
|
@ -14,9 +15,11 @@ public class GuiImplosionCompressor extends GuiContainer{
|
||||||
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/implosion_compressor.png");
|
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/implosion_compressor.png");
|
||||||
|
|
||||||
TileImplosionCompressor compresser;
|
TileImplosionCompressor compresser;
|
||||||
|
ContainerImplosionCompressor containerImplosionCompressor;
|
||||||
|
|
||||||
public GuiImplosionCompressor(EntityPlayer player, TileImplosionCompressor tilecompresser) {
|
public GuiImplosionCompressor(EntityPlayer player, TileImplosionCompressor tilecompresser) {
|
||||||
super(new ContainerImplosionCompressor(tilecompresser, player));
|
super(new ContainerImplosionCompressor(tilecompresser, player));
|
||||||
|
containerImplosionCompressor = (ContainerImplosionCompressor) this.inventorySlots;
|
||||||
this.xSize = 176;
|
this.xSize = 176;
|
||||||
this.ySize = 167;
|
this.ySize = 167;
|
||||||
compresser = tilecompresser;
|
compresser = tilecompresser;
|
||||||
|
@ -39,13 +42,16 @@ public class GuiImplosionCompressor extends GuiContainer{
|
||||||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
if(this.containerImplosionCompressor.currentTickTime != 0){
|
||||||
if(compresser.crafter.currentRecipe != null) {
|
j = this.containerImplosionCompressor.currentTickTime * 20 / this.containerImplosionCompressor.currentNeededTicks;
|
||||||
j = this.compresser.crafter.currentTickTime * 20 / this.compresser.crafter.currentRecipe.tickTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(this.containerImplosionCompressor.currentTickTime);
|
||||||
|
|
||||||
this.drawTexturedModalRect(k + 60, l + 38, 176, 14, j + 1, 16);
|
this.drawTexturedModalRect(k + 60, l + 38, 176, 14, j + 1, 16);
|
||||||
|
|
||||||
j = (int)this.compresser.energy.getEnergyStored() * 12 / this.compresser.energy.getCapacity();
|
j = this.containerImplosionCompressor.energy * 12 / this.compresser.energy.getCapacity();
|
||||||
if(j > 0) {
|
if(j > 0) {
|
||||||
this.drawTexturedModalRect(k + 16, l + 37 + 12 - j, 176, 12 - j, 14, j + 2);
|
this.drawTexturedModalRect(k + 16, l + 37 + 12 - j, 176, 12 - j, 14, j + 2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue