Remove old upgrade handler to make way for the new one.

This commit is contained in:
modmuss50 2017-04-11 00:12:36 +01:00
parent 8c3be8366a
commit 34978f7ffe
10 changed files with 25 additions and 166 deletions

View file

@ -26,8 +26,8 @@ package techreborn.api.gui;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import reborncore.api.tile.IUpgrade;
import reborncore.client.gui.slots.BaseSlot;
import techreborn.utils.upgrade.IMachineUpgrade;
public class SlotUpgrade extends BaseSlot {
@ -37,6 +37,6 @@ public class SlotUpgrade extends BaseSlot {
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() instanceof IMachineUpgrade;
return stack.getItem() instanceof IUpgrade;
}
}

View file

@ -37,6 +37,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.api.power.IEnergyInterfaceItem;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IUpgrade;
import reborncore.client.gui.slots.BaseSlot;
import reborncore.client.gui.slots.SlotFake;
import reborncore.client.gui.slots.SlotOutput;
@ -44,7 +45,6 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.Core;
import techreborn.client.container.builder.slot.FilteredSlot;
import techreborn.utils.upgrade.IMachineUpgrade;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
@ -107,7 +107,7 @@ public class ContainerTileInventoryBuilder {
public ContainerTileInventoryBuilder upgradeSlot(final int index, final int x, final int y) {
this.parent.slots.add(new FilteredSlot(this.tile, index, x, y)
.setFilter(stack -> stack.getItem() instanceof IMachineUpgrade));
.setFilter(stack -> stack.getItem() instanceof IUpgrade));
return this;
}

View file

@ -34,12 +34,11 @@ import net.minecraft.util.text.translation.I18n;
import reborncore.common.recipes.RecipeCrafter;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;
import techreborn.utils.upgrade.IMachineUpgrade;
import java.security.InvalidParameterException;
import java.util.List;
public class ItemUpgrades extends ItemTRNoDestroy implements IMachineUpgrade {
public class ItemUpgrades extends ItemTRNoDestroy {
public static final String[] types = new String[] { "overclock", "transformer", "energy_storage", "range" };
@ -81,25 +80,25 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IMachineUpgrade {
}
}
@Override
public void processUpgrade(RecipeCrafter crafter, ItemStack stack) {
// Remember the max speed multiplier can only be 0.99!!
if (stack.getItemDamage() == 0) {// Check the meta data here
crafter.addSpeedMulti(0.2);// This will set the speed multiplier to
// 0.8
crafter.addPowerMulti(0.5);// This will use eu/tick x 1.5
// crafter.addPowerMulti(2); This will use twice the amount of
// power.
}
if (stack.getItemDamage() == 1) {
crafter.addPowerMulti(-0.2);// This will use eu/tick 0.8
}
if (stack.getItemDamage() == 2) {
crafter.addSpeedMulti(0.5);
crafter.addPowerMulti(1);
}
}
// @Override
// public void processUpgrade(RecipeCrafter crafter, ItemStack stack) {
// // Remember the max speed multiplier can only be 0.99!!
//
// if (stack.getItemDamage() == 0) {// Check the meta data here
// crafter.addSpeedMulti(0.2);// This will set the speed multiplier to
// // 0.8
// crafter.addPowerMulti(0.5);// This will use eu/tick x 1.5
// // crafter.addPowerMulti(2); This will use twice the amount of
// // power.
// }
// if (stack.getItemDamage() == 1) {
// crafter.addPowerMulti(-0.2);// This will use eu/tick 0.8
// }
// if (stack.getItemDamage() == 2) {
// crafter.addSpeedMulti(0.5);
// crafter.addPowerMulti(1);
// }
// }
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {

View file

@ -46,7 +46,6 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileAlloySmelter extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider, IContainerProvider {
@ -55,7 +54,6 @@ public class TileAlloySmelter extends TilePowerAcceptor
public Inventory inventory = new Inventory(8, "TileAlloySmelter", 64, this);
public RecipeCrafter crafter;
public int capacity = 1000;
UpgradeHandler upgrades;
public TileAlloySmelter() {
super(1);
@ -66,14 +64,12 @@ public class TileAlloySmelter extends TilePowerAcceptor
final int[] outputs = new int[1];
outputs[0] = 2;
this.crafter = new RecipeCrafter(Reference.alloySmelteRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgrades = new UpgradeHandler(this.crafter, this.inventory, 4, 5, 6, 7);
}
@Override
public void update() {
super.update();
this.crafter.updateEntity();
this.upgrades.tick();
this.charge(3);
}

View file

@ -39,13 +39,11 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileCompressor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileCompressor", 64, this);
public UpgradeHandler upgradeHandler;
public RecipeCrafter crafter;
public int capacity = 1000;
@ -55,7 +53,7 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 };
this.crafter = new RecipeCrafter(Reference.compressorRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 2, 3, 4, 5);
}
@Override
@ -63,7 +61,6 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
if (!this.world.isRemote) {
super.update();
this.crafter.updateEntity();
this.upgradeHandler.tick();
this.charge(3);
}
}

View file

@ -40,14 +40,12 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileExtractor extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileExtractor", 64, this);
public UpgradeHandler upgradeHandler;
public RecipeCrafter crafter;
public int capacity = 1000;
@ -59,7 +57,6 @@ public class TileExtractor extends TilePowerAcceptor
final int[] outputs = new int[1];
outputs[0] = 1;
this.crafter = new RecipeCrafter(Reference.extractorRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 2, 3, 4, 5);
}
@Override
@ -67,7 +64,6 @@ public class TileExtractor extends TilePowerAcceptor
if (!this.world.isRemote) {
super.update();
this.crafter.updateEntity();
this.upgradeHandler.tick();
this.charge(3);
}
}

View file

@ -42,14 +42,12 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileGrinder extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
public UpgradeHandler upgradeHandler;
public RecipeCrafter crafter;
public int capacity = 1000;
@ -61,14 +59,12 @@ implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerPr
final int[] outputs = new int[1];
outputs[0] = 1;
this.crafter = new RecipeCrafter(Reference.grinderRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 2, 3, 4, 5);
}
@Override
public void update() {
if (!this.world.isRemote) {
super.update();
this.upgradeHandler.tick();
//charge(3); TODO
this.charge(3);
}

View file

@ -1,33 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.utils.upgrade;
import net.minecraft.item.ItemStack;
import reborncore.common.recipes.RecipeCrafter;
public interface IMachineUpgrade {
public void processUpgrade(RecipeCrafter crafter, ItemStack stack);
}

View file

@ -1,64 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.utils.upgrade;
import net.minecraft.item.ItemStack;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import java.util.ArrayList;
public class UpgradeHandler {
RecipeCrafter crafter;
Inventory inventory;
ArrayList<Integer> slots = new ArrayList<>();
public UpgradeHandler(RecipeCrafter crafter, Inventory inventory, int... slots) {
this.crafter = crafter;
this.inventory = inventory;
for (int slot : slots) {
this.slots.add(slot);
}
}
public void tick() {
if (crafter.parentTile.getWorld().isRemote)
return;
crafter.resetPowerMulti();
crafter.resetSpeedMulti();
for (int slot : this.slots) {
ItemStack stack = inventory.getStackInSlot(slot);
if (stack != ItemStack.EMPTY && stack.getItem() instanceof IMachineUpgrade) {
((IMachineUpgrade) stack.getItem()).processUpgrade(crafter, stack);
}
}
if (crafter.currentRecipe != null)
crafter.currentNeededTicks = (int) (crafter.currentRecipe.tickTime()
* (1.0 - crafter.getSpeedMultiplier()));
}
}

View file

@ -1,28 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
package techreborn.utils.upgrade;
import net.minecraftforge.fml.common.API;