Convert RollingMachine
This commit is contained in:
parent
8a0a133e02
commit
ad890079ec
8 changed files with 140 additions and 185 deletions
|
@ -1,111 +0,0 @@
|
|||
package techreborn.client.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.gui.slots.BaseSlot;
|
||||
import reborncore.client.gui.slots.SlotOutput;
|
||||
import reborncore.common.container.RebornContainer;
|
||||
import techreborn.api.RollingMachineRecipe;
|
||||
import techreborn.tiles.TileRollingMachine;
|
||||
|
||||
public class ContainerRollingMachine extends RebornContainer {
|
||||
|
||||
EntityPlayer player;
|
||||
TileRollingMachine tile;
|
||||
int currentItemBurnTime;
|
||||
int burnTime;
|
||||
int energy;
|
||||
|
||||
public ContainerRollingMachine(TileRollingMachine tileRollingmachine, EntityPlayer player) {
|
||||
tile = tileRollingmachine;
|
||||
this.player = player;
|
||||
|
||||
for (int l = 0; l < 3; l++) {
|
||||
for (int k1 = 0; k1 < 3; k1++) {
|
||||
this.addSlotToContainer(
|
||||
new BaseSlot(tileRollingmachine.craftMatrix, k1 + l * 3, 30 + k1 * 18, 17 + l * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// output
|
||||
this.addSlotToContainer(new SlotOutput(tileRollingmachine.inventory, 0, 124, 35));
|
||||
// battery
|
||||
this.addSlotToContainer(new BaseSlot(tileRollingmachine.inventory, 2, 8, 51));
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onCraftMatrixChanged(IInventory inv) {
|
||||
ItemStack output = RollingMachineRecipe.instance.findMatchingRecipe(tile.craftMatrix, tile.getWorld());
|
||||
tile.inventory.setInventorySlotContents(1, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(IContainerListener crafting) {
|
||||
super.addListener(crafting);
|
||||
crafting.sendProgressBarUpdate(this, 0, tile.runTime);
|
||||
crafting.sendProgressBarUpdate(this, 1, tile.tickTime);
|
||||
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
for (int i = 0; i < this.listeners.size(); i++) {
|
||||
IContainerListener crafting = this.listeners.get(i);
|
||||
if (this.currentItemBurnTime != tile.runTime) {
|
||||
crafting.sendProgressBarUpdate(this, 0, tile.runTime);
|
||||
}
|
||||
if (this.burnTime != tile.tickTime || tile.tickTime == -1) {
|
||||
crafting.sendProgressBarUpdate(this, 1, tile.tickTime);
|
||||
}
|
||||
if (this.energy != (int) tile.getEnergy()) {
|
||||
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
|
||||
}
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int id, int value) {
|
||||
super.updateProgressBar(id, value);
|
||||
if (id == 0) {
|
||||
this.currentItemBurnTime = value;
|
||||
} else if (id == 1) {
|
||||
this.burnTime = value;
|
||||
} else if (id == 2) {
|
||||
this.energy = value;
|
||||
}
|
||||
this.tile.runTime = this.currentItemBurnTime;
|
||||
if (this.burnTime == -1) {
|
||||
this.burnTime = 0;
|
||||
}
|
||||
this.tile.tickTime = this.burnTime;
|
||||
this.tile.setEnergy(this.energy);
|
||||
}
|
||||
|
||||
public int getBurnTimeRemainingScaled(int scale) {
|
||||
if (burnTime == 0 || this.currentItemBurnTime == 0) {
|
||||
return 0;
|
||||
}
|
||||
return this.burnTime * scale / this.currentItemBurnTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,9 +5,7 @@ import org.apache.commons.lang3.tuple.MutableTriple;
|
|||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
@ -16,6 +14,7 @@ import reborncore.common.util.ItemUtils;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -30,6 +29,7 @@ public class BuiltContainer extends Container {
|
|||
|
||||
private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Short>> shortValues;
|
||||
private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Integer>> integerValues;
|
||||
private List<Consumer<InventoryCrafting>> craftEvents;
|
||||
private Integer[] integerParts;
|
||||
|
||||
public BuiltContainer(final String name, final Predicate<EntityPlayer> canInteract,
|
||||
|
@ -61,6 +61,10 @@ public class BuiltContainer extends Container {
|
|||
this.integerParts = new Integer[this.integerValues.size()];
|
||||
}
|
||||
|
||||
public void addCraftEvents(final List<Consumer<InventoryCrafting>> craftEvents) {
|
||||
this.craftEvents = craftEvents;
|
||||
}
|
||||
|
||||
public void addSlot(final Slot slot) {
|
||||
this.addSlotToContainer(slot);
|
||||
}
|
||||
|
@ -70,6 +74,16 @@ public class BuiltContainer extends Container {
|
|||
return this.canInteract.test(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onCraftMatrixChanged(final IInventory inv) {
|
||||
if (!this.craftEvents.isEmpty())
|
||||
this.craftEvents.forEach(consumer -> consumer.accept((InventoryCrafting) inv));
|
||||
// final ItemStack output =
|
||||
// RollingMachineRecipe.instance.findMatchingRecipe(this.tile.craftMatrix,
|
||||
// this.tile.getWorld());
|
||||
// this.tile.inventory.setInventorySlotContents(1, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
|
|
@ -6,10 +6,12 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -17,6 +19,7 @@ import java.util.function.Predicate;
|
|||
public class ContainerBuilder {
|
||||
|
||||
private final String name;
|
||||
|
||||
private Predicate<EntityPlayer> canInteract = player -> true;
|
||||
|
||||
final List<Slot> slots;
|
||||
|
@ -25,6 +28,8 @@ public class ContainerBuilder {
|
|||
final List<Pair<IntSupplier, IntConsumer>> shortValues;
|
||||
final List<Pair<IntSupplier, IntConsumer>> integerValues;
|
||||
|
||||
final List<Consumer<InventoryCrafting>> craftEvents;
|
||||
|
||||
public ContainerBuilder(final String name) {
|
||||
|
||||
this.name = name;
|
||||
|
@ -35,6 +40,8 @@ public class ContainerBuilder {
|
|||
|
||||
this.shortValues = new ArrayList<>();
|
||||
this.integerValues = new ArrayList<>();
|
||||
|
||||
this.craftEvents = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ContainerBuilder interact(final Predicate<EntityPlayer> canInteract) {
|
||||
|
@ -59,12 +66,15 @@ public class ContainerBuilder {
|
|||
}
|
||||
|
||||
public BuiltContainer create() {
|
||||
final BuiltContainer built = new BuiltContainer(this.name, this.canInteract, this.playerInventoryRanges,
|
||||
final BuiltContainer built = new BuiltContainer(this.name, this.canInteract,
|
||||
this.playerInventoryRanges,
|
||||
this.tileInventoryRanges);
|
||||
if (!this.shortValues.isEmpty())
|
||||
built.addShortSync(this.shortValues);
|
||||
if (!this.integerValues.isEmpty())
|
||||
built.addIntegerSync(this.integerValues);
|
||||
if (!this.craftEvents.isEmpty())
|
||||
built.addCraftEvents(this.craftEvents);
|
||||
|
||||
this.slots.forEach(built::addSlot);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.apache.commons.lang3.Range;
|
|||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.SlotFurnaceFuel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -21,6 +22,7 @@ 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;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -133,6 +135,11 @@ public class ContainerTileInventoryBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ContainerTileInventoryBuilder onCraft(final Consumer<InventoryCrafting> onCraft) {
|
||||
this.parent.craftEvents.add(onCraft);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContainerBuilder addInventory() {
|
||||
this.parent.tileInventoryRanges.add(Range.between(this.rangeStart, this.parent.slots.size() - 1));
|
||||
return this.parent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue