mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
properly fix #1157
This commit is contained in:
parent
614d6e41c4
commit
33d9cb9fdb
30 changed files with 874 additions and 920 deletions
|
@ -41,7 +41,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class ContainerBag extends Container implements IButtonReactor{
|
public class ContainerBag extends Container implements IButtonReactor {
|
||||||
|
|
||||||
public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000);
|
public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000);
|
||||||
private final ItemStackHandlerAA bagInventory;
|
private final ItemStackHandlerAA bagInventory;
|
||||||
|
@ -51,36 +51,29 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
private boolean oldAutoInsert;
|
private boolean oldAutoInsert;
|
||||||
private final ItemStack sack;
|
private final ItemStack sack;
|
||||||
|
|
||||||
public ContainerBag(ItemStack sack, InventoryPlayer inventory, boolean isVoid){
|
public ContainerBag(ItemStack sack, InventoryPlayer inventory, boolean isVoid) {
|
||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid)) {
|
this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid), (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE);
|
||||||
@Override
|
|
||||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
|
||||||
if(isBlacklisted(stack)) return stack;
|
|
||||||
return super.insertItem(slot, stack, simulate);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
this.isVoid = isVoid;
|
this.isVoid = isVoid;
|
||||||
this.sack = sack;
|
this.sack = sack;
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++){
|
for (int i = 0; i < 4; i++) {
|
||||||
this.addSlotToContainer(new SlotFilter(this.filter, i, 155, 10+i*18));
|
this.addSlotToContainer(new SlotFilter(this.filter, i, 155, 10 + i * 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.isVoid){
|
if (this.isVoid) {
|
||||||
this.addSlotToContainer(new SlotDeletion(this.bagInventory, 0, 64, 65){
|
this.addSlotToContainer(new SlotDeletion(this.bagInventory, 0, 64, 65) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack){
|
public boolean isItemValid(ItemStack stack) {
|
||||||
return ContainerBag.this.filter.check(stack);
|
return ContainerBag.this.filter.check(stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else{
|
for (int i = 0; i < 4; i++) {
|
||||||
for(int i = 0; i < 4; i++){
|
for (int j = 0; j < 7; j++) {
|
||||||
for(int j = 0; j < 7; j++){
|
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) {
|
||||||
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.bagInventory, j+i*7, 10+j*18, 10+i*18){
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack){
|
public boolean isItemValid(ItemStack stack) {
|
||||||
return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack);
|
return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -88,24 +81,23 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++){
|
for (int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 9; j++){
|
for (int j = 0; j < 9; j++) {
|
||||||
this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 94+i*18));
|
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i = 0; i < 9; i++){
|
for (int i = 0; i < 9; i++) {
|
||||||
if(i == inventory.currentItem){
|
if (i == inventory.currentItem) {
|
||||||
this.addSlotToContainer(new SlotImmovable(inventory, i, 8+i*18, 152));
|
this.addSlotToContainer(new SlotImmovable(inventory, i, 8 + i * 18, 152));
|
||||||
}
|
} else {
|
||||||
else{
|
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 152));
|
||||||
this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 152));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = inventory.getCurrentItem();
|
ItemStack stack = inventory.getCurrentItem();
|
||||||
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){
|
if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) {
|
||||||
ItemDrill.loadSlotsFromNBT(this.bagInventory, inventory.getCurrentItem());
|
ItemDrill.loadSlotsFromNBT(this.bagInventory, inventory.getCurrentItem());
|
||||||
if(stack.hasTagCompound()){
|
if (stack.hasTagCompound()) {
|
||||||
NBTTagCompound compound = stack.getTagCompound();
|
NBTTagCompound compound = stack.getTagCompound();
|
||||||
this.filter.readFromNBT(compound, "Filter");
|
this.filter.readFromNBT(compound, "Filter");
|
||||||
this.autoInsert = compound.getBoolean("AutoInsert");
|
this.autoInsert = compound.getBoolean("AutoInsert");
|
||||||
|
@ -113,16 +105,16 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSlotAmount(boolean isVoid){
|
public static int getSlotAmount(boolean isVoid) {
|
||||||
return isVoid ? 1 : 28;
|
return isVoid ? 1 : 28;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detectAndSendChanges(){
|
public void detectAndSendChanges() {
|
||||||
super.detectAndSendChanges();
|
super.detectAndSendChanges();
|
||||||
|
|
||||||
if(this.filter.needsUpdateSend() || this.autoInsert != this.oldAutoInsert){
|
if (this.filter.needsUpdateSend() || this.autoInsert != this.oldAutoInsert) {
|
||||||
for(IContainerListener listener : this.listeners){
|
for (IContainerListener listener : this.listeners) {
|
||||||
listener.sendWindowProperty(this, 0, this.filter.isWhitelist ? 1 : 0);
|
listener.sendWindowProperty(this, 0, this.filter.isWhitelist ? 1 : 0);
|
||||||
listener.sendWindowProperty(this, 1, this.filter.respectMeta ? 1 : 0);
|
listener.sendWindowProperty(this, 1, this.filter.respectMeta ? 1 : 0);
|
||||||
listener.sendWindowProperty(this, 2, this.filter.respectNBT ? 1 : 0);
|
listener.sendWindowProperty(this, 2, this.filter.respectNBT ? 1 : 0);
|
||||||
|
@ -137,70 +129,54 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void updateProgressBar(int id, int data){
|
public void updateProgressBar(int id, int data) {
|
||||||
if(id == 0){
|
if (id == 0) {
|
||||||
this.filter.isWhitelist = data == 1;
|
this.filter.isWhitelist = data == 1;
|
||||||
}
|
} else if (id == 1) {
|
||||||
else if(id == 1){
|
|
||||||
this.filter.respectMeta = data == 1;
|
this.filter.respectMeta = data == 1;
|
||||||
}
|
} else if (id == 2) {
|
||||||
else if(id == 2){
|
|
||||||
this.filter.respectNBT = data == 1;
|
this.filter.respectNBT = data == 1;
|
||||||
}
|
} else if (id == 3) {
|
||||||
else if(id == 3){
|
|
||||||
this.filter.respectOredict = data;
|
this.filter.respectOredict = data;
|
||||||
}
|
} else if (id == 4) {
|
||||||
else if(id == 4){
|
|
||||||
this.autoInsert = data == 1;
|
this.autoInsert = data == 1;
|
||||||
}
|
} else if (id == 5) {
|
||||||
else if(id == 5){
|
|
||||||
this.filter.respectMod = data == 1;
|
this.filter.respectMod = data == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
|
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
|
||||||
int inventoryStart = this.bagInventory.getSlots()+4;
|
int inventoryStart = this.bagInventory.getSlots() + 4;
|
||||||
int inventoryEnd = inventoryStart+26;
|
int inventoryEnd = inventoryStart + 26;
|
||||||
int hotbarStart = inventoryEnd+1;
|
int hotbarStart = inventoryEnd + 1;
|
||||||
int hotbarEnd = hotbarStart+8;
|
int hotbarEnd = hotbarStart + 8;
|
||||||
|
|
||||||
Slot theSlot = this.inventorySlots.get(slot);
|
Slot theSlot = this.inventorySlots.get(slot);
|
||||||
|
|
||||||
if(theSlot != null && theSlot.getHasStack()){
|
if (theSlot != null && theSlot.getHasStack()) {
|
||||||
ItemStack newStack = theSlot.getStack();
|
ItemStack newStack = theSlot.getStack();
|
||||||
ItemStack currentStack = newStack.copy();
|
ItemStack currentStack = newStack.copy();
|
||||||
|
|
||||||
//Other Slots in Inventory excluded
|
//Other Slots in Inventory excluded
|
||||||
if(slot >= inventoryStart){
|
if (slot >= inventoryStart) {
|
||||||
//Shift from Inventory
|
//Shift from Inventory
|
||||||
if(this.isVoid || !this.filter.check(newStack) || !this.mergeItemStack(newStack, 4, 32, false)){
|
if (this.isVoid || !this.filter.check(newStack) || !this.mergeItemStack(newStack, 4, 32, false)) {
|
||||||
if(slot >= inventoryStart && slot <= inventoryEnd){
|
if (slot >= inventoryStart && slot <= inventoryEnd) {
|
||||||
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
|
if (!this.mergeItemStack(newStack, hotbarStart, hotbarEnd + 1, false)) { return StackUtil.getEmpty(); }
|
||||||
return StackUtil.getEmpty();
|
} else if (slot >= inventoryEnd + 1 && slot < hotbarEnd + 1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd + 1, false)) { return StackUtil.getEmpty(); }
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
|
|
||||||
return StackUtil.getEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
}
|
} else if (!this.mergeItemStack(newStack, inventoryStart, hotbarEnd + 1, false)) { return StackUtil.getEmpty(); }
|
||||||
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
|
|
||||||
return StackUtil.getEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!StackUtil.isValid(newStack)){
|
if (!StackUtil.isValid(newStack)) {
|
||||||
theSlot.putStack(StackUtil.getEmpty());
|
theSlot.putStack(StackUtil.getEmpty());
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
theSlot.onSlotChanged();
|
theSlot.onSlotChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newStack.getCount() == currentStack.getCount()){
|
if (newStack.getCount() == currentStack.getCount()) { return StackUtil.getEmpty(); }
|
||||||
return StackUtil.getEmpty();
|
|
||||||
}
|
|
||||||
theSlot.onTake(player, newStack);
|
theSlot.onTake(player, newStack);
|
||||||
|
|
||||||
return currentStack;
|
return currentStack;
|
||||||
|
@ -209,22 +185,20 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
|
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
|
||||||
if(SlotFilter.checkFilter(this, slotId, player)){
|
if (SlotFilter.checkFilter(this, slotId, player)) {
|
||||||
return StackUtil.getEmpty();
|
return StackUtil.getEmpty();
|
||||||
}
|
} else if (clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem) {
|
||||||
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
|
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onContainerClosed(EntityPlayer player){
|
public void onContainerClosed(EntityPlayer player) {
|
||||||
ItemStack stack = this.inventory.getCurrentItem();
|
ItemStack stack = this.inventory.getCurrentItem();
|
||||||
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){
|
if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) {
|
||||||
ItemDrill.writeSlotsToNBT(this.bagInventory, this.inventory.getCurrentItem());
|
ItemDrill.writeSlotsToNBT(this.bagInventory, this.inventory.getCurrentItem());
|
||||||
NBTTagCompound compound = stack.getTagCompound();
|
NBTTagCompound compound = stack.getTagCompound();
|
||||||
this.filter.writeToNBT(compound, "Filter");
|
this.filter.writeToNBT(compound, "Filter");
|
||||||
|
@ -234,16 +208,15 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer player){
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
return !sack.isEmpty() && player.getHeldItemMainhand() == sack;
|
return !sack.isEmpty() && player.getHeldItemMainhand() == sack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
if(buttonID == 0){
|
if (buttonID == 0) {
|
||||||
this.autoInsert = !this.autoInsert;
|
this.autoInsert = !this.autoInsert;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.filter.onButtonPressed(buttonID);
|
this.filter.onButtonPressed(buttonID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,18 +226,17 @@ public class ContainerBag extends Container implements IButtonReactor{
|
||||||
private static boolean runOnce = false;
|
private static boolean runOnce = false;
|
||||||
|
|
||||||
public static boolean isBlacklisted(ItemStack stack) {
|
public static boolean isBlacklisted(ItemStack stack) {
|
||||||
if(!runOnce) {
|
if (!runOnce) {
|
||||||
runOnce = true;
|
runOnce = true;
|
||||||
for(String s : ConfigStringListValues.SACK_BLACKLIST.getValue()) {
|
for (String s : ConfigStringListValues.SACK_BLACKLIST.getValue()) {
|
||||||
String[] split = s.split("@");
|
String[] split = s.split("@");
|
||||||
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0]));
|
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0]));
|
||||||
if(item == null) {
|
if (item == null) {
|
||||||
ActuallyAdditions.LOGGER.error("Invalid item in sack blacklist: " + s);
|
ActuallyAdditions.LOGGER.error("Invalid item in sack blacklist: " + s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(split.length == 1)
|
if (split.length == 1) BLACKLIST.add(Pair.of(item, 0));
|
||||||
BLACKLIST.add(Pair.of(item, 0));
|
else if (split.length == 2) {
|
||||||
else if(split.length == 2) {
|
|
||||||
BLACKLIST.add(Pair.of(item, Integer.parseInt(split[1])));
|
BLACKLIST.add(Pair.of(item, Integer.parseInt(split[1])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@ import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
|
@ -143,13 +143,8 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation) {
|
public IAcceptor getAcceptor() {
|
||||||
return StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
|
return (slot, stack, automation) -> StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ItemBattery;
|
import de.ellpeck.actuallyadditions.mod.items.ItemBattery;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -144,13 +145,8 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
|
public IAcceptor getAcceptor(){
|
||||||
return true;
|
return (slot, stack, automation) -> stack.getItem() instanceof ItemBattery;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation){
|
|
||||||
return stack.getItem() instanceof ItemBattery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,6 +10,12 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.IGrowable;
|
import net.minecraft.block.IGrowable;
|
||||||
|
@ -23,10 +29,7 @@ import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.common.IPlantable;
|
import net.minecraftforge.common.IPlantable;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class TileEntityBioReactor extends TileEntityInventoryBase implements ISharingEnergyProvider {
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TileEntityBioReactor extends TileEntityInventoryBase implements ISharingEnergyProvider{
|
|
||||||
|
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 0, 800);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 0, 800);
|
||||||
|
|
||||||
|
@ -37,41 +40,38 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
||||||
private int lastBurnTime;
|
private int lastBurnTime;
|
||||||
private int lastProducePerTick;
|
private int lastProducePerTick;
|
||||||
|
|
||||||
public TileEntityBioReactor(){
|
public TileEntityBioReactor() {
|
||||||
super(8, "bioReactor");
|
super(8, "bioReactor");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidItem(ItemStack stack){
|
public static boolean isValidItem(ItemStack stack) {
|
||||||
if(StackUtil.isValid(stack)){
|
if (StackUtil.isValid(stack)) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if(isValid(item)){
|
if (isValid(item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (item instanceof ItemBlock) { return isValid(Block.getBlockFromItem(item)); }
|
||||||
else if(item instanceof ItemBlock){
|
|
||||||
return isValid(Block.getBlockFromItem(item));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValid(Object o){
|
private static boolean isValid(Object o) {
|
||||||
return o instanceof IPlantable || o instanceof IGrowable || o instanceof ItemFood;
|
return o instanceof IPlantable || o instanceof IGrowable || o instanceof ItemFood;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if(this.burnTime <= 0){
|
if (this.burnTime <= 0) {
|
||||||
List<Item> types = null;
|
List<Item> types = null;
|
||||||
|
|
||||||
if(!this.isRedstonePowered && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
|
if (!this.isRedstonePowered && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()) {
|
||||||
for(int i = 0; i < this.inv.getSlots(); i++){
|
for (int i = 0; i < this.inv.getSlots(); i++) {
|
||||||
ItemStack stack = this.inv.getStackInSlot(i);
|
ItemStack stack = this.inv.getStackInSlot(i);
|
||||||
if(StackUtil.isValid(stack)){
|
if (StackUtil.isValid(stack)) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if(isValidItem(stack) && (types == null || !types.contains(item))){
|
if (isValidItem(stack) && (types == null || !types.contains(item))) {
|
||||||
if(types == null){
|
if (types == null) {
|
||||||
types = new ArrayList<Item>();
|
types = new ArrayList<Item>();
|
||||||
}
|
}
|
||||||
types.add(item);
|
types.add(item);
|
||||||
|
@ -84,32 +84,30 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(types != null && !types.isEmpty()){
|
if (types != null && !types.isEmpty()) {
|
||||||
int amount = types.size();
|
int amount = types.size();
|
||||||
this.producePerTick = (int)Math.pow(amount*2, 2);
|
this.producePerTick = (int) Math.pow(amount * 2, 2);
|
||||||
|
|
||||||
this.maxBurnTime = 200-(int)Math.pow(1.8, amount);
|
this.maxBurnTime = 200 - (int) Math.pow(1.8, amount);
|
||||||
this.burnTime = this.maxBurnTime;
|
this.burnTime = this.maxBurnTime;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.burnTime = 0;
|
this.burnTime = 0;
|
||||||
this.maxBurnTime = 0;
|
this.maxBurnTime = 0;
|
||||||
this.producePerTick = 0;
|
this.producePerTick = 0;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.burnTime--;
|
this.burnTime--;
|
||||||
this.storage.receiveEnergyInternal(this.producePerTick, false);
|
this.storage.receiveEnergyInternal(this.producePerTick, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.lastBurnTime != this.burnTime || this.lastProducePerTick != this.producePerTick) && this.sendUpdateWithInterval()){
|
if ((this.lastBurnTime != this.burnTime || this.lastProducePerTick != this.producePerTick) && this.sendUpdateWithInterval()) {
|
||||||
this.lastBurnTime = this.burnTime;
|
this.lastBurnTime = this.burnTime;
|
||||||
this.lastProducePerTick = this.producePerTick;
|
this.lastProducePerTick = this.producePerTick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
|
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
|
@ -119,7 +117,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
|
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
|
@ -129,43 +127,43 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int index, ItemStack stack, boolean byAutomation){
|
public IAcceptor getAcceptor() {
|
||||||
return false;
|
return (slot, stack, automation) -> isValidItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int index, ItemStack stack, boolean fromAutomation){
|
public IRemover getRemover() {
|
||||||
return isValidItem(stack);
|
return ItemStackHandlerAA.REMOVE_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyToSplitShare(){
|
public int getEnergyToSplitShare() {
|
||||||
return this.storage.getEnergyStored();
|
return this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesShareEnergy(){
|
public boolean doesShareEnergy() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumFacing[] getEnergyShareSides(){
|
public EnumFacing[] getEnergyShareSides() {
|
||||||
return EnumFacing.values();
|
return EnumFacing.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canShareTo(TileEntity tile){
|
public boolean canShareTo(TileEntity tile) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getComparatorStrength(){
|
public int getComparatorStrength() {
|
||||||
float calc = ((float)this.storage.getEnergyStored()/(float)this.storage.getMaxEnergyStored())*15F;
|
float calc = ((float) this.storage.getEnergyStored() / (float) this.storage.getMaxEnergyStored()) * 15F;
|
||||||
return (int)calc;
|
return (int) calc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -71,9 +72,8 @@ public class TileEntityBreaker extends TileEntityInventoryBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean automation) {
|
public IAcceptor getAcceptor() {
|
||||||
if(isPlacer) return true;
|
return (slot, stack, automation) -> !automation;
|
||||||
else return !automation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWork() {
|
private void doWork() {
|
||||||
|
@ -96,7 +96,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase {
|
||||||
}
|
}
|
||||||
} else if (this.isPlacer) {
|
} else if (this.isPlacer) {
|
||||||
int slot = StackUtil.findFirstFilled(inv);
|
int slot = StackUtil.findFirstFilled(inv);
|
||||||
if(slot == -1) return;
|
if (slot == -1) return;
|
||||||
this.inv.setStackInSlot(slot, WorldUtil.useItemAtSide(side, world, pos, inv.getStackInSlot(slot)));
|
this.inv.setStackInSlot(slot, WorldUtil.useItemAtSide(side, world, pos, inv.getStackInSlot(slot)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -24,15 +26,15 @@ import net.minecraftforge.fluids.FluidTank;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class TileEntityCanolaPress extends TileEntityInventoryBase implements ISharingFluidHandler{
|
public class TileEntityCanolaPress extends TileEntityInventoryBase implements ISharingFluidHandler {
|
||||||
|
|
||||||
public static final int PRODUCE = 80;
|
public static final int PRODUCE = 80;
|
||||||
public static final int ENERGY_USE = 35;
|
public static final int ENERGY_USE = 35;
|
||||||
private static final int TIME = 30;
|
private static final int TIME = 30;
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(40000, 100, 0);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(40000, 100, 0);
|
||||||
public final FluidTank tank = new FluidTank(2*Util.BUCKET){
|
public final FluidTank tank = new FluidTank(2 * Util.BUCKET) {
|
||||||
@Override
|
@Override
|
||||||
public boolean canFill(){
|
public boolean canFill() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -41,28 +43,28 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
|
||||||
private int lastTankAmount;
|
private int lastTankAmount;
|
||||||
private int lastProcessTime;
|
private int lastProcessTime;
|
||||||
|
|
||||||
public TileEntityCanolaPress(){
|
public TileEntityCanolaPress() {
|
||||||
super(1, "canolaPress");
|
super(1, "canolaPress");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getTankScaled(int i){
|
public int getTankScaled(int i) {
|
||||||
return this.tank.getFluidAmount()*i/this.tank.getCapacity();
|
return this.tank.getFluidAmount() * i / this.tank.getCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getProcessScaled(int i){
|
public int getProcessScaled(int i) {
|
||||||
return this.currentProcessTime*i/TIME;
|
return this.currentProcessTime * i / TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("ProcessTime", this.currentProcessTime);
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
||||||
}
|
}
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
|
@ -71,8 +73,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.currentProcessTime = compound.getInteger("ProcessTime");
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
||||||
}
|
}
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
|
@ -81,14 +83,14 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(isCanola(inv.getStackInSlot(0)) && PRODUCE <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
if (isCanola(inv.getStackInSlot(0)) && PRODUCE <= this.tank.getCapacity() - this.tank.getFluidAmount()) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
this.currentProcessTime++;
|
this.currentProcessTime++;
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
if(this.currentProcessTime >= TIME){
|
if (this.currentProcessTime >= TIME) {
|
||||||
this.currentProcessTime = 0;
|
this.currentProcessTime = 0;
|
||||||
|
|
||||||
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
|
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
|
||||||
|
@ -97,12 +99,11 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.currentProcessTime = 0;
|
this.currentProcessTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
|
if ((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergyStored = this.storage.getEnergyStored();
|
this.lastEnergyStored = this.storage.getEnergyStored();
|
||||||
this.lastProcessTime = this.currentProcessTime;
|
this.lastProcessTime = this.currentProcessTime;
|
||||||
this.lastTankAmount = this.tank.getFluidAmount();
|
this.lastTankAmount = this.tank.getFluidAmount();
|
||||||
|
@ -111,41 +112,41 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation){
|
public IAcceptor getAcceptor() {
|
||||||
return (slot == 0 && isCanola(stack));
|
return (slot, stack, automation) -> slot == 0 && isCanola(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCanola(ItemStack stack){
|
public static boolean isCanola(ItemStack stack) {
|
||||||
return stack.getItem() == InitItems.itemMisc && stack.getMetadata() == TheMiscItems.CANOLA.ordinal();
|
return stack.getItem() == InitItems.itemMisc && stack.getMetadata() == TheMiscItems.CANOLA.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
|
public IRemover getRemover() {
|
||||||
return !byAutomation;
|
return (slot, automation) -> !automation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank getFluidHandler(EnumFacing facing){
|
public FluidTank getFluidHandler(EnumFacing facing) {
|
||||||
return this.tank;
|
return this.tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFluidAmountToSplitShare(){
|
public int getMaxFluidAmountToSplitShare() {
|
||||||
return this.tank.getFluidAmount();
|
return this.tank.getFluidAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesShareFluid(){
|
public boolean doesShareFluid() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumFacing[] getFluidShareSides(){
|
public EnumFacing[] getFluidShareSides() {
|
||||||
return EnumFacing.values();
|
return EnumFacing.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
@ -19,7 +21,7 @@ import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements ISharingEnergyProvider{
|
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements ISharingEnergyProvider {
|
||||||
|
|
||||||
public static final int PRODUCE = 30;
|
public static final int PRODUCE = 30;
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(60000, 0, 80);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(60000, 0, 80);
|
||||||
|
@ -30,23 +32,23 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
||||||
private int lastCurrentBurnTime;
|
private int lastCurrentBurnTime;
|
||||||
private int lastCompare;
|
private int lastCompare;
|
||||||
|
|
||||||
public TileEntityCoalGenerator(){
|
public TileEntityCoalGenerator() {
|
||||||
super(1, "coalGenerator");
|
super(1, "coalGenerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getBurningScaled(int i){
|
public int getBurningScaled(int i) {
|
||||||
return this.currentBurnTime*i/this.maxBurnTime;
|
return this.currentBurnTime * i / this.maxBurnTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("BurnTime", this.currentBurnTime);
|
compound.setInteger("BurnTime", this.currentBurnTime);
|
||||||
compound.setInteger("MaxBurnTime", this.maxBurnTime);
|
compound.setInteger("MaxBurnTime", this.maxBurnTime);
|
||||||
}
|
}
|
||||||
|
@ -55,8 +57,8 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.currentBurnTime = compound.getInteger("BurnTime");
|
this.currentBurnTime = compound.getInteger("BurnTime");
|
||||||
this.maxBurnTime = compound.getInteger("MaxBurnTime");
|
this.maxBurnTime = compound.getInteger("MaxBurnTime");
|
||||||
}
|
}
|
||||||
|
@ -65,32 +67,32 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
boolean flag = this.currentBurnTime > 0;
|
boolean flag = this.currentBurnTime > 0;
|
||||||
|
|
||||||
if(this.currentBurnTime > 0){
|
if (this.currentBurnTime > 0) {
|
||||||
this.currentBurnTime--;
|
this.currentBurnTime--;
|
||||||
this.storage.receiveEnergyInternal(PRODUCE, false);
|
this.storage.receiveEnergyInternal(PRODUCE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = inv.getStackInSlot(0);
|
ItemStack stack = inv.getStackInSlot(0);
|
||||||
int burn = TileEntityFurnace.getItemBurnTime(stack);
|
int burn = TileEntityFurnace.getItemBurnTime(stack);
|
||||||
if(!this.isRedstonePowered && this.currentBurnTime <= 0 && burn > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
|
if (!this.isRedstonePowered && this.currentBurnTime <= 0 && burn > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()) {
|
||||||
this.maxBurnTime = burn;
|
this.maxBurnTime = burn;
|
||||||
this.currentBurnTime = burn;
|
this.currentBurnTime = burn;
|
||||||
ItemStack copy = stack.copy();
|
ItemStack copy = stack.copy();
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
if(stack.isEmpty()) inv.setStackInSlot(0, copy.getItem().getContainerItem(copy));
|
if (stack.isEmpty()) inv.setStackInSlot(0, copy.getItem().getContainerItem(copy));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()){
|
if (flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()) {
|
||||||
this.lastCompare = this.getComparatorStrength();
|
this.lastCompare = this.getComparatorStrength();
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()){
|
if ((this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
this.lastCurrentBurnTime = this.currentBurnTime;
|
this.lastCurrentBurnTime = this.currentBurnTime;
|
||||||
this.lastBurnTime = this.currentBurnTime;
|
this.lastBurnTime = this.currentBurnTime;
|
||||||
|
@ -99,44 +101,46 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getComparatorStrength(){
|
public int getComparatorStrength() {
|
||||||
float calc = ((float)this.storage.getEnergyStored()/(float)this.storage.getMaxEnergyStored())*15F;
|
float calc = ((float) this.storage.getEnergyStored() / (float) this.storage.getMaxEnergyStored()) * 15F;
|
||||||
return (int)calc;
|
return (int) calc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation){
|
public IAcceptor getAcceptor() {
|
||||||
return TileEntityFurnace.getItemBurnTime(stack) > 0;
|
return (slot, stack, automation) -> TileEntityFurnace.getItemBurnTime(stack) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation){
|
public IRemover getRemover() {
|
||||||
if(!byAutomation) return true;
|
return (slot, automation) -> {
|
||||||
|
if (!automation) return true;
|
||||||
return TileEntityFurnace.getItemBurnTime(this.inv.getStackInSlot(0)) <= 0;
|
return TileEntityFurnace.getItemBurnTime(this.inv.getStackInSlot(0)) <= 0;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyToSplitShare(){
|
public int getEnergyToSplitShare() {
|
||||||
return this.storage.getEnergyStored();
|
return this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesShareEnergy(){
|
public boolean doesShareEnergy() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumFacing[] getEnergyShareSides(){
|
public EnumFacing[] getEnergyShareSides() {
|
||||||
return EnumFacing.values();
|
return EnumFacing.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canShareTo(TileEntity tile){
|
public boolean canShareTo(TileEntity tile) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ import de.ellpeck.actuallyadditions.mod.items.ItemCoffee;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -30,7 +32,7 @@ import net.minecraftforge.fluids.FluidTank;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, ISharingFluidHandler{
|
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, ISharingFluidHandler {
|
||||||
|
|
||||||
public static final int SLOT_COFFEE_BEANS = 0;
|
public static final int SLOT_COFFEE_BEANS = 0;
|
||||||
public static final int SLOT_INPUT = 1;
|
public static final int SLOT_INPUT = 1;
|
||||||
|
@ -41,14 +43,14 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
||||||
public static final int COFFEE_CACHE_MAX_AMOUNT = 300;
|
public static final int COFFEE_CACHE_MAX_AMOUNT = 300;
|
||||||
private static final int TIME_USED = 500;
|
private static final int TIME_USED = 500;
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 250, 0);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 250, 0);
|
||||||
public final FluidTank tank = new FluidTank(4*Util.BUCKET){
|
public final FluidTank tank = new FluidTank(4 * Util.BUCKET) {
|
||||||
@Override
|
@Override
|
||||||
public boolean canDrain(){
|
public boolean canDrain() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canFillFluidType(FluidStack fluid){
|
public boolean canFillFluidType(FluidStack fluid) {
|
||||||
return fluid.getFluid() == FluidRegistry.WATER;
|
return fluid.getFluid() == FluidRegistry.WATER;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -59,63 +61,63 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
||||||
private int lastCoffeeAmount;
|
private int lastCoffeeAmount;
|
||||||
private int lastBrewTime;
|
private int lastBrewTime;
|
||||||
|
|
||||||
public TileEntityCoffeeMachine(){
|
public TileEntityCoffeeMachine() {
|
||||||
super(11, "coffeeMachine");
|
super(11, "coffeeMachine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getCoffeeScaled(int i){
|
public int getCoffeeScaled(int i) {
|
||||||
return this.coffeeCacheAmount*i/COFFEE_CACHE_MAX_AMOUNT;
|
return this.coffeeCacheAmount * i / COFFEE_CACHE_MAX_AMOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getWaterScaled(int i){
|
public int getWaterScaled(int i) {
|
||||||
return this.tank.getFluidAmount()*i/this.tank.getCapacity();
|
return this.tank.getFluidAmount() * i / this.tank.getCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getBrewScaled(int i){
|
public int getBrewScaled(int i) {
|
||||||
return this.brewTime*i/TIME_USED;
|
return this.brewTime * i / TIME_USED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
this.tank.writeToNBT(compound);
|
this.tank.writeToNBT(compound);
|
||||||
compound.setInteger("Cache", this.coffeeCacheAmount);
|
compound.setInteger("Cache", this.coffeeCacheAmount);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("Time", this.brewTime);
|
compound.setInteger("Time", this.brewTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
this.tank.readFromNBT(compound);
|
this.tank.readFromNBT(compound);
|
||||||
this.coffeeCacheAmount = compound.getInteger("Cache");
|
this.coffeeCacheAmount = compound.getInteger("Cache");
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.brewTime = compound.getInteger("Time");
|
this.brewTime = compound.getInteger("Time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
this.storeCoffee();
|
this.storeCoffee();
|
||||||
|
|
||||||
if(this.brewTime > 0 || this.isRedstonePowered){
|
if (this.brewTime > 0 || this.isRedstonePowered) {
|
||||||
this.brew();
|
this.brew();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.coffeeCacheAmount != this.lastCoffeeAmount || this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.brewTime != this.lastBrewTime) && this.sendUpdateWithInterval()){
|
if ((this.coffeeCacheAmount != this.lastCoffeeAmount || this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.brewTime != this.lastBrewTime) && this.sendUpdateWithInterval()) {
|
||||||
this.lastCoffeeAmount = this.coffeeCacheAmount;
|
this.lastCoffeeAmount = this.coffeeCacheAmount;
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
this.lastTank = this.tank.getFluidAmount();
|
this.lastTank = this.tank.getFluidAmount();
|
||||||
|
@ -125,39 +127,44 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return (i >= 3 && ItemCoffee.getIngredientFromStack(stack) != null) || (i == SLOT_COFFEE_BEANS && stack.getItem() == InitItems.itemCoffeeBean) || (i == SLOT_INPUT && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CUP.ordinal());
|
return (slot, stack, automation) -> (slot >= 3 && ItemCoffee.getIngredientFromStack(stack) != null) || (slot == SLOT_COFFEE_BEANS && stack.getItem() == InitItems.itemCoffeeBean) || (slot == SLOT_INPUT && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CUP.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeCoffee(){
|
@Override
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(SLOT_COFFEE_BEANS)) && this.inv.getStackInSlot(SLOT_COFFEE_BEANS).getItem() == InitItems.itemCoffeeBean){
|
public IRemover getRemover() {
|
||||||
|
return (slot, automation) -> slot == SLOT_OUTPUT || (slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientFromStack(inv.getStackInSlot(slot)) == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void storeCoffee() {
|
||||||
|
if (StackUtil.isValid(this.inv.getStackInSlot(SLOT_COFFEE_BEANS)) && this.inv.getStackInSlot(SLOT_COFFEE_BEANS).getItem() == InitItems.itemCoffeeBean) {
|
||||||
int toAdd = 2;
|
int toAdd = 2;
|
||||||
if(toAdd <= COFFEE_CACHE_MAX_AMOUNT-this.coffeeCacheAmount){
|
if (toAdd <= COFFEE_CACHE_MAX_AMOUNT - this.coffeeCacheAmount) {
|
||||||
this.inv.setStackInSlot(SLOT_COFFEE_BEANS, StackUtil.shrink(this.inv.getStackInSlot(SLOT_COFFEE_BEANS), 1));
|
this.inv.setStackInSlot(SLOT_COFFEE_BEANS, StackUtil.shrink(this.inv.getStackInSlot(SLOT_COFFEE_BEANS), 1));
|
||||||
this.coffeeCacheAmount += toAdd;
|
this.coffeeCacheAmount += toAdd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void brew(){
|
public void brew() {
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
ItemStack input = this.inv.getStackInSlot(SLOT_INPUT);
|
ItemStack input = this.inv.getStackInSlot(SLOT_INPUT);
|
||||||
if (StackUtil.isValid(input) && input.getItem() == InitItems.itemMisc && input.getItemDamage() == TheMiscItems.CUP.ordinal() && !StackUtil.isValid(this.inv.getStackInSlot(SLOT_OUTPUT)) && this.coffeeCacheAmount >= CACHE_USE && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == FluidRegistry.WATER && this.tank.getFluidAmount() >= WATER_USE){
|
if (StackUtil.isValid(input) && input.getItem() == InitItems.itemMisc && input.getItemDamage() == TheMiscItems.CUP.ordinal() && !StackUtil.isValid(this.inv.getStackInSlot(SLOT_OUTPUT)) && this.coffeeCacheAmount >= CACHE_USE && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == FluidRegistry.WATER && this.tank.getFluidAmount() >= WATER_USE) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USED){
|
if (this.storage.getEnergyStored() >= ENERGY_USED) {
|
||||||
if(this.brewTime%30 == 0){
|
if (this.brewTime % 30 == 0) {
|
||||||
this.world.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.coffeeMachine, SoundCategory.BLOCKS, 0.35F, 1.0F);
|
this.world.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.coffeeMachine, SoundCategory.BLOCKS, 0.35F, 1.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.brewTime++;
|
this.brewTime++;
|
||||||
this.storage.extractEnergyInternal(ENERGY_USED, false);
|
this.storage.extractEnergyInternal(ENERGY_USED, false);
|
||||||
if(this.brewTime >= TIME_USED){
|
if (this.brewTime >= TIME_USED) {
|
||||||
this.brewTime = 0;
|
this.brewTime = 0;
|
||||||
ItemStack output = new ItemStack(InitItems.itemCoffee);
|
ItemStack output = new ItemStack(InitItems.itemCoffee);
|
||||||
for(int i = 3; i < this.inv.getSlots(); i++){
|
for (int i = 3; i < this.inv.getSlots(); i++) {
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(i))){
|
if (StackUtil.isValid(this.inv.getStackInSlot(i))) {
|
||||||
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.inv.getStackInSlot(i));
|
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.inv.getStackInSlot(i));
|
||||||
if(ingredient != null){
|
if (ingredient != null) {
|
||||||
if(ingredient.effect(output)){
|
if (ingredient.effect(output)) {
|
||||||
this.inv.setStackInSlot(i, StackUtil.shrinkForContainer(this.inv.getStackInSlot(i), 1));
|
this.inv.setStackInSlot(i, StackUtil.shrinkForContainer(this.inv.getStackInSlot(i), 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,47 +176,41 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
||||||
this.tank.drainInternal(WATER_USE, true);
|
this.tank.drainInternal(WATER_USE, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.brewTime = 0;
|
this.brewTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
return slot == SLOT_OUTPUT || (slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientFromStack(stack) == null);
|
if (buttonID == 0 && this.brewTime <= 0) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
|
||||||
if(buttonID == 0 && this.brewTime <= 0){
|
|
||||||
this.brew();
|
this.brew();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank getFluidHandler(EnumFacing facing){
|
public FluidTank getFluidHandler(EnumFacing facing) {
|
||||||
return this.tank;
|
return this.tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFluidAmountToSplitShare(){
|
public int getMaxFluidAmountToSplitShare() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesShareFluid(){
|
public boolean doesShareFluid() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumFacing[] getFluidShareSides(){
|
public EnumFacing[] getFluidShareSides() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -90,13 +92,13 @@ public class TileEntityCompost extends TileEntityInventoryBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation) {
|
public IAcceptor getAcceptor() {
|
||||||
return getRecipeForInput(stack) != null;
|
return (slot, stack, automation) -> getRecipeForInput(stack) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
|
public IRemover getRemover() {
|
||||||
return getRecipeForInput(stack) == null;
|
return (slot, automation) -> getRecipeForInput(inv.getStackInSlot(slot)) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBlockState getCurrentDisplay() {
|
public IBlockState getCurrentDisplay() {
|
||||||
|
@ -109,7 +111,7 @@ public class TileEntityCompost extends TileEntityInventoryBase {
|
||||||
else if (r.getInput().apply(input)) return r.getInputDisplay();
|
else if (r.getInput().apply(input)) return r.getInputDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(displayRecipe != null) return displayRecipe.getInputDisplay();
|
if (displayRecipe != null) return displayRecipe.getInputDisplay();
|
||||||
return Blocks.AIR.getDefaultState();
|
return Blocks.AIR.getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -21,7 +22,7 @@ import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
|
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase {
|
||||||
|
|
||||||
public static final int RANGE = 8;
|
public static final int RANGE = 8;
|
||||||
public static final int ENERGY_USE = 5;
|
public static final int ENERGY_USE = 5;
|
||||||
|
@ -29,66 +30,65 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
|
||||||
private int lastEnergy;
|
private int lastEnergy;
|
||||||
private int currentTime;
|
private int currentTime;
|
||||||
|
|
||||||
public TileEntityDirectionalBreaker(){
|
public TileEntityDirectionalBreaker() {
|
||||||
super(9, "directionalBreaker");
|
super(9, "directionalBreaker");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("CurrentTime", this.currentTime);
|
compound.setInteger("CurrentTime", this.currentTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.currentTime = compound.getInteger("CurrentTime");
|
this.currentTime = compound.getInteger("CurrentTime");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(!this.isRedstonePowered && !this.isPulseMode){
|
if (!this.isRedstonePowered && !this.isPulseMode) {
|
||||||
if(this.currentTime > 0){
|
if (this.currentTime > 0) {
|
||||||
this.currentTime--;
|
this.currentTime--;
|
||||||
if(this.currentTime <= 0){
|
if (this.currentTime <= 0) {
|
||||||
this.doWork();
|
this.doWork();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.currentTime = 15;
|
this.currentTime = 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() != this.lastEnergy && this.sendUpdateWithInterval()){
|
if (this.storage.getEnergyStored() != this.lastEnergy && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWork(){
|
private void doWork() {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE * RANGE) {
|
||||||
IBlockState state = this.world.getBlockState(this.pos);
|
IBlockState state = this.world.getBlockState(this.pos);
|
||||||
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state);
|
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state);
|
||||||
|
|
||||||
for(int i = 0; i < RANGE; i++){
|
for (int i = 0; i < RANGE; i++) {
|
||||||
BlockPos coordsBlock = this.pos.offset(sideToManipulate, i+1);
|
BlockPos coordsBlock = this.pos.offset(sideToManipulate, i + 1);
|
||||||
IBlockState breakState = world.getBlockState(coordsBlock);
|
IBlockState breakState = world.getBlockState(coordsBlock);
|
||||||
Block blockToBreak = breakState.getBlock();
|
Block blockToBreak = breakState.getBlock();
|
||||||
if(blockToBreak != null && !this.world.isAirBlock(coordsBlock) && this.world.getBlockState(coordsBlock).getBlockHardness(this.world, coordsBlock) > -1.0F){
|
if (blockToBreak != null && !this.world.isAirBlock(coordsBlock) && this.world.getBlockState(coordsBlock).getBlockHardness(this.world, coordsBlock) > -1.0F) {
|
||||||
NonNullList<ItemStack> drops = NonNullList.create();
|
NonNullList<ItemStack> drops = NonNullList.create();
|
||||||
blockToBreak.getDrops(drops, world, coordsBlock, breakState, 0);
|
blockToBreak.getDrops(drops, world, coordsBlock, breakState, 0);
|
||||||
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, this.world, coordsBlock);
|
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, this.world, coordsBlock);
|
||||||
|
|
||||||
if(chance > 0 && this.world.rand.nextFloat() <= chance){
|
if (chance > 0 && this.world.rand.nextFloat() <= chance) {
|
||||||
if(StackUtil.canAddAll(this.inv, drops, false)){
|
if (StackUtil.canAddAll(this.inv, drops, false)) {
|
||||||
this.world.playEvent(2001, coordsBlock, Block.getStateId(this.world.getBlockState(coordsBlock)));
|
this.world.playEvent(2001, coordsBlock, Block.getStateId(this.world.getBlockState(coordsBlock)));
|
||||||
this.world.setBlockToAir(coordsBlock);
|
this.world.setBlockToAir(coordsBlock);
|
||||||
StackUtil.addAll(this.inv, drops, false);
|
StackUtil.addAll(this.inv, drops, false);
|
||||||
|
@ -102,31 +102,26 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation;
|
return (slot, stack, automation) -> !automation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public boolean isRedstoneToggle() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRedstoneToggle(){
|
public void activateOnPulse() {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void activateOnPulse(){
|
|
||||||
this.doWork();
|
this.doWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -50,7 +52,8 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPossibleInput(ItemStack stack) {
|
public static boolean isPossibleInput(ItemStack stack) {
|
||||||
for(EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) if(r.getInput().apply(stack)) return true;
|
for (EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES)
|
||||||
|
if (r.getInput().apply(stack)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,13 +156,13 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int index, ItemStack stack, boolean automation) {
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || !getRecipesForInput(stack).isEmpty();
|
return (slot, stack, automation) -> !automation || isPossibleInput(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int index, ItemStack stack, boolean automation) {
|
public IRemover getRemover() {
|
||||||
return !automation || getRecipesForInput(stack).isEmpty();
|
return (slot, automation) -> !automation || !isPossibleInput(inv.getStackInSlot(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,84 +10,85 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
public class TileEntityEnergizer extends TileEntityInventoryBase{
|
public class TileEntityEnergizer extends TileEntityInventoryBase {
|
||||||
|
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 1000, 0);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 1000, 0);
|
||||||
private int lastEnergy;
|
private int lastEnergy;
|
||||||
|
|
||||||
public TileEntityEnergizer(){
|
public TileEntityEnergizer() {
|
||||||
super(2, "energizer");
|
super(2, "energizer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(0)) && !StackUtil.isValid(this.inv.getStackInSlot(1))){
|
if (StackUtil.isValid(this.inv.getStackInSlot(0)) && !StackUtil.isValid(this.inv.getStackInSlot(1))) {
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if (this.storage.getEnergyStored() > 0) {
|
||||||
int received = 0;
|
int received = 0;
|
||||||
boolean canTakeUp = false;
|
boolean canTakeUp = false;
|
||||||
|
|
||||||
if(this.inv.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)){
|
if (this.inv.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)) {
|
||||||
IEnergyStorage cap = this.inv.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
|
IEnergyStorage cap = this.inv.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
|
||||||
if(cap != null){
|
if (cap != null) {
|
||||||
received = cap.receiveEnergy(this.storage.getEnergyStored(), false);
|
received = cap.receiveEnergy(this.storage.getEnergyStored(), false);
|
||||||
canTakeUp = cap.getEnergyStored() >= cap.getMaxEnergyStored();
|
canTakeUp = cap.getEnergyStored() >= cap.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(received > 0){
|
if (received > 0) {
|
||||||
this.storage.extractEnergyInternal(received, false);
|
this.storage.extractEnergyInternal(received, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(canTakeUp){
|
if (canTakeUp) {
|
||||||
this.inv.setStackInSlot(1, this.inv.getStackInSlot(0).copy());
|
this.inv.setStackInSlot(1, this.inv.getStackInSlot(0).copy());
|
||||||
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
|
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if (this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || (i == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
|
return (slot, stack, automation) -> !automation || (slot == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !EnchantmentHelper.hasBindingCurse(stack) && !automation || (slot == 1);
|
return (slot, automation) -> !EnchantmentHelper.hasBindingCurse(inv.getStackInSlot(slot)) && !automation || (slot == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,105 +10,106 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
public class TileEntityEnervator extends TileEntityInventoryBase implements ISharingEnergyProvider{
|
public class TileEntityEnervator extends TileEntityInventoryBase implements ISharingEnergyProvider {
|
||||||
|
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, 1000);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, 1000);
|
||||||
private int lastEnergy;
|
private int lastEnergy;
|
||||||
|
|
||||||
public TileEntityEnervator(){
|
public TileEntityEnervator() {
|
||||||
super(2, "enervator");
|
super(2, "enervator");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(0)) && !StackUtil.isValid(this.inv.getStackInSlot(1))){
|
if (StackUtil.isValid(this.inv.getStackInSlot(0)) && !StackUtil.isValid(this.inv.getStackInSlot(1))) {
|
||||||
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
|
if (this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()) {
|
||||||
int extracted = 0;
|
int extracted = 0;
|
||||||
boolean canTakeUp = false;
|
boolean canTakeUp = false;
|
||||||
|
|
||||||
int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored();
|
int maxExtract = this.storage.getMaxEnergyStored() - this.storage.getEnergyStored();
|
||||||
if(this.inv.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)){
|
if (this.inv.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)) {
|
||||||
IEnergyStorage cap = this.inv.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
|
IEnergyStorage cap = this.inv.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
|
||||||
if(cap != null){
|
if (cap != null) {
|
||||||
extracted = cap.extractEnergy(maxExtract, false);
|
extracted = cap.extractEnergy(maxExtract, false);
|
||||||
canTakeUp = cap.getEnergyStored() <= 0;
|
canTakeUp = cap.getEnergyStored() <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(extracted > 0){
|
if (extracted > 0) {
|
||||||
this.storage.receiveEnergyInternal(extracted, false);
|
this.storage.receiveEnergyInternal(extracted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(canTakeUp){
|
if (canTakeUp) {
|
||||||
this.inv.setStackInSlot(1, this.inv.getStackInSlot(0).copy());
|
this.inv.setStackInSlot(1, this.inv.getStackInSlot(0).copy());
|
||||||
this.inv.getStackInSlot(0).shrink(1);
|
this.inv.getStackInSlot(0).shrink(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if (this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || (i == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
|
return (slot, stack, automation) -> !automation || (slot == 0 && (stack.hasCapability(CapabilityEnergy.ENERGY, null)));
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnergyScaled(int i){
|
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation || slot == 1;
|
return (slot, automation) -> !automation || slot == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnergyScaled(int i) {
|
||||||
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyToSplitShare(){
|
public int getEnergyToSplitShare() {
|
||||||
return this.storage.getEnergyStored();
|
return this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesShareEnergy(){
|
public boolean doesShareEnergy() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumFacing[] getEnergyShareSides(){
|
public EnumFacing[] getEnergyShareSides() {
|
||||||
return EnumFacing.values();
|
return EnumFacing.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canShareTo(TileEntity tile){
|
public boolean canShareTo(TileEntity tile) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -138,13 +140,13 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation) {
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || i < 6;
|
return (slot, stack, automation) -> !automation || slot < 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
|
public IRemover getRemover() {
|
||||||
return !automation || slot >= 6;
|
return (slot, automation) -> !automation || slot >= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import net.minecraft.entity.passive.EntityAnimal;
|
import net.minecraft.entity.passive.EntityAnimal;
|
||||||
import net.minecraft.entity.passive.EntityHorse;
|
import net.minecraft.entity.passive.EntityHorse;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
|
@ -23,7 +24,7 @@ import net.minecraft.util.EnumParticleTypes;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class TileEntityFeeder extends TileEntityInventoryBase{
|
public class TileEntityFeeder extends TileEntityInventoryBase {
|
||||||
|
|
||||||
public static final int THRESHOLD = 30;
|
public static final int THRESHOLD = 30;
|
||||||
private static final int TIME = 100;
|
private static final int TIME = 100;
|
||||||
|
@ -32,45 +33,45 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
|
||||||
private int lastAnimalAmount;
|
private int lastAnimalAmount;
|
||||||
private int lastTimer;
|
private int lastTimer;
|
||||||
|
|
||||||
public TileEntityFeeder(){
|
public TileEntityFeeder() {
|
||||||
super(1, "feeder");
|
super(1, "feeder");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentTimerToScale(int i){
|
public int getCurrentTimerToScale(int i) {
|
||||||
return this.currentTimer*i/TIME;
|
return this.currentTimer * i / TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
compound.setInteger("Timer", this.currentTimer);
|
compound.setInteger("Timer", this.currentTimer);
|
||||||
if(type == NBTType.SYNC){
|
if (type == NBTType.SYNC) {
|
||||||
compound.setInteger("Animals", this.currentAnimalAmount);
|
compound.setInteger("Animals", this.currentAnimalAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
this.currentTimer = compound.getInteger("Timer");
|
this.currentTimer = compound.getInteger("Timer");
|
||||||
if(type == NBTType.SYNC){
|
if (type == NBTType.SYNC) {
|
||||||
this.currentAnimalAmount = compound.getInteger("Animals");
|
this.currentAnimalAmount = compound.getInteger("Animals");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
currentTimer = MathHelper.clamp(++currentTimer, 0, 100);
|
currentTimer = MathHelper.clamp(++currentTimer, 0, 100);
|
||||||
if(world.isRemote) return;
|
if (world.isRemote) return;
|
||||||
int range = 5;
|
int range = 5;
|
||||||
ItemStack stack = this.inv.getStackInSlot(0);
|
ItemStack stack = this.inv.getStackInSlot(0);
|
||||||
if(!stack.isEmpty() && this.currentTimer >= TIME) {
|
if (!stack.isEmpty() && this.currentTimer >= TIME) {
|
||||||
List<EntityAnimal> animals = this.world.getEntitiesWithinAABB(EntityAnimal.class, new AxisAlignedBB(this.pos.getX()-range, this.pos.getY()-range, this.pos.getZ()-range, this.pos.getX()+range, this.pos.getY()+range, this.pos.getZ()+range));
|
List<EntityAnimal> animals = this.world.getEntitiesWithinAABB(EntityAnimal.class, new AxisAlignedBB(this.pos.getX() - range, this.pos.getY() - range, this.pos.getZ() - range, this.pos.getX() + range, this.pos.getY() + range, this.pos.getZ() + range));
|
||||||
this.currentAnimalAmount = animals.size();
|
this.currentAnimalAmount = animals.size();
|
||||||
if(currentAnimalAmount >= 2 && currentAnimalAmount < THRESHOLD){
|
if (currentAnimalAmount >= 2 && currentAnimalAmount < THRESHOLD) {
|
||||||
Optional<EntityAnimal> opt = animals.stream().filter((e) -> canBeFed(stack, e)).findAny();
|
Optional<EntityAnimal> opt = animals.stream().filter((e) -> canBeFed(stack, e)).findAny();
|
||||||
if(opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
feedAnimal(opt.get());
|
feedAnimal(opt.get());
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
this.currentTimer = 0;
|
this.currentTimer = 0;
|
||||||
|
@ -78,29 +79,29 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((this.lastAnimalAmount != this.currentAnimalAmount || this.lastTimer != this.currentTimer) && this.sendUpdateWithInterval()){
|
if ((this.lastAnimalAmount != this.currentAnimalAmount || this.lastTimer != this.currentTimer) && this.sendUpdateWithInterval()) {
|
||||||
this.lastAnimalAmount = this.currentAnimalAmount;
|
this.lastAnimalAmount = this.currentAnimalAmount;
|
||||||
this.lastTimer = this.currentTimer;
|
this.lastTimer = this.currentTimer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation;
|
return (slot, automation) -> !automation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void feedAnimal(EntityAnimal animal){
|
private static void feedAnimal(EntityAnimal animal) {
|
||||||
animal.setInLove(null);
|
animal.setInLove(null);
|
||||||
for(int i = 0; i < 7; i++){
|
for (int i = 0; i < 7; i++) {
|
||||||
double d = animal.world.rand.nextGaussian()*0.02D;
|
double d = animal.world.rand.nextGaussian() * 0.02D;
|
||||||
double d1 = animal.world.rand.nextGaussian()*0.02D;
|
double d1 = animal.world.rand.nextGaussian() * 0.02D;
|
||||||
double d2 = animal.world.rand.nextGaussian()*0.02D;
|
double d2 = animal.world.rand.nextGaussian() * 0.02D;
|
||||||
animal.world.spawnParticle(EnumParticleTypes.HEART, (animal.posX+(double)(animal.world.rand.nextFloat()*animal.width*2.0F))-animal.width, animal.posY+0.5D+(double)(animal.world.rand.nextFloat()*animal.height), (animal.posZ+(double)(animal.world.rand.nextFloat()*animal.width*2.0F))-animal.width, d, d1, d2);
|
animal.world.spawnParticle(EnumParticleTypes.HEART, (animal.posX + (double) (animal.world.rand.nextFloat() * animal.width * 2.0F)) - animal.width, animal.posY + 0.5D + (double) (animal.world.rand.nextFloat() * animal.height), (animal.posZ + (double) (animal.world.rand.nextFloat() * animal.width * 2.0F)) - animal.width, d, d1, d2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean canBeFed(ItemStack stack, EntityAnimal animal){
|
private static boolean canBeFed(ItemStack stack, EntityAnimal animal) {
|
||||||
if(animal instanceof EntityHorse && ((EntityHorse) animal).isTame()){
|
if (animal instanceof EntityHorse && ((EntityHorse) animal).isTame()) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
return (animal.getGrowingAge() == 0 && !animal.isInLove()) && (item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT);
|
return (animal.getGrowingAge() == 0 && !animal.isInLove()) && (item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -23,7 +25,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements IButtonReactor{
|
public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements IButtonReactor {
|
||||||
|
|
||||||
public static final int SLOT_INPUT_1 = 0;
|
public static final int SLOT_INPUT_1 = 0;
|
||||||
public static final int SLOT_OUTPUT_1 = 1;
|
public static final int SLOT_OUTPUT_1 = 1;
|
||||||
|
@ -41,34 +43,32 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
private boolean lastAutoSplit;
|
private boolean lastAutoSplit;
|
||||||
private boolean lastSmelted;
|
private boolean lastSmelted;
|
||||||
|
|
||||||
public TileEntityFurnaceDouble(){
|
public TileEntityFurnaceDouble() {
|
||||||
super(4, "furnaceDouble");
|
super(4, "furnaceDouble");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void autoSplit(ItemStackHandlerAA inv, int slot1, int slot2){
|
public static void autoSplit(ItemStackHandlerAA inv, int slot1, int slot2) {
|
||||||
ItemStack first = inv.getStackInSlot(slot1);
|
ItemStack first = inv.getStackInSlot(slot1);
|
||||||
ItemStack second = inv.getStackInSlot(slot2);
|
ItemStack second = inv.getStackInSlot(slot2);
|
||||||
|
|
||||||
if(StackUtil.isValid(first) || StackUtil.isValid(second)){
|
if (StackUtil.isValid(first) || StackUtil.isValid(second)) {
|
||||||
ItemStack toSplit = StackUtil.getEmpty();
|
ItemStack toSplit = StackUtil.getEmpty();
|
||||||
if(!StackUtil.isValid(first) && StackUtil.isValid(second) && second.getCount() > 1){
|
if (!StackUtil.isValid(first) && StackUtil.isValid(second) && second.getCount() > 1) {
|
||||||
toSplit = second;
|
toSplit = second;
|
||||||
}
|
} else if (!StackUtil.isValid(second) && StackUtil.isValid(first) && first.getCount() > 1) {
|
||||||
else if(!StackUtil.isValid(second) && StackUtil.isValid(first) && first.getCount() > 1){
|
|
||||||
toSplit = first;
|
toSplit = first;
|
||||||
}
|
} else if (ItemUtil.canBeStacked(first, second)) {
|
||||||
else if(ItemUtil.canBeStacked(first, second)){
|
if (first.getCount() < first.getMaxStackSize() || second.getCount() < second.getMaxStackSize()) {
|
||||||
if(first.getCount() < first.getMaxStackSize() || second.getCount() < second.getMaxStackSize()){
|
if (!((first.getCount() <= second.getCount() + 1 && first.getCount() >= second.getCount() - 1) || (second.getCount() <= first.getCount() + 1 && second.getCount() >= first.getCount() - 1))) {
|
||||||
if(!((first.getCount() <= second.getCount()+1 && first.getCount() >= second.getCount()-1) || (second.getCount() <= first.getCount()+1 && second.getCount() >= first.getCount()-1))){
|
|
||||||
toSplit = first;
|
toSplit = first;
|
||||||
toSplit.grow(second.getCount());
|
toSplit.grow(second.getCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StackUtil.isValid(toSplit)){
|
if (StackUtil.isValid(toSplit)) {
|
||||||
ItemStack splitFirst = toSplit.copy();
|
ItemStack splitFirst = toSplit.copy();
|
||||||
ItemStack secondSplit = splitFirst.splitStack(splitFirst.getCount()/2);
|
ItemStack secondSplit = splitFirst.splitStack(splitFirst.getCount() / 2);
|
||||||
inv.setStackInSlot(slot1, splitFirst);
|
inv.setStackInSlot(slot1, splitFirst);
|
||||||
inv.setStackInSlot(slot2, secondSplit);
|
inv.setStackInSlot(slot2, secondSplit);
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("FirstSmeltTime", this.firstSmeltTime);
|
compound.setInteger("FirstSmeltTime", this.firstSmeltTime);
|
||||||
compound.setInteger("SecondSmeltTime", this.secondSmeltTime);
|
compound.setInteger("SecondSmeltTime", this.secondSmeltTime);
|
||||||
compound.setBoolean("IsAutoSplit", this.isAutoSplit);
|
compound.setBoolean("IsAutoSplit", this.isAutoSplit);
|
||||||
|
@ -87,9 +87,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.firstSmeltTime = compound.getInteger("FirstSmeltTime");
|
this.firstSmeltTime = compound.getInteger("FirstSmeltTime");
|
||||||
this.secondSmeltTime = compound.getInteger("SecondSmeltTime");
|
this.secondSmeltTime = compound.getInteger("SecondSmeltTime");
|
||||||
this.isAutoSplit = compound.getBoolean("IsAutoSplit");
|
this.isAutoSplit = compound.getBoolean("IsAutoSplit");
|
||||||
|
@ -98,10 +98,10 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(this.isAutoSplit){
|
if (this.isAutoSplit) {
|
||||||
autoSplit(this.inv, SLOT_INPUT_1, SLOT_INPUT_2);
|
autoSplit(this.inv, SLOT_INPUT_1, SLOT_INPUT_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,46 +110,44 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
boolean canSmeltOnFirst = this.canSmeltOn(SLOT_INPUT_1, SLOT_OUTPUT_1);
|
boolean canSmeltOnFirst = this.canSmeltOn(SLOT_INPUT_1, SLOT_OUTPUT_1);
|
||||||
boolean canSmeltOnSecond = this.canSmeltOn(SLOT_INPUT_2, SLOT_OUTPUT_2);
|
boolean canSmeltOnSecond = this.canSmeltOn(SLOT_INPUT_2, SLOT_OUTPUT_2);
|
||||||
|
|
||||||
if(canSmeltOnFirst){
|
if (canSmeltOnFirst) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
this.firstSmeltTime++;
|
this.firstSmeltTime++;
|
||||||
if(this.firstSmeltTime >= SMELT_TIME){
|
if (this.firstSmeltTime >= SMELT_TIME) {
|
||||||
this.finishBurning(SLOT_INPUT_1, SLOT_OUTPUT_1);
|
this.finishBurning(SLOT_INPUT_1, SLOT_OUTPUT_1);
|
||||||
this.firstSmeltTime = 0;
|
this.firstSmeltTime = 0;
|
||||||
}
|
}
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
}
|
}
|
||||||
smelted = true;
|
smelted = true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.firstSmeltTime = 0;
|
this.firstSmeltTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(canSmeltOnSecond){
|
if (canSmeltOnSecond) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
this.secondSmeltTime++;
|
this.secondSmeltTime++;
|
||||||
if(this.secondSmeltTime >= SMELT_TIME){
|
if (this.secondSmeltTime >= SMELT_TIME) {
|
||||||
this.finishBurning(SLOT_INPUT_2, SLOT_OUTPUT_2);
|
this.finishBurning(SLOT_INPUT_2, SLOT_OUTPUT_2);
|
||||||
this.secondSmeltTime = 0;
|
this.secondSmeltTime = 0;
|
||||||
}
|
}
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
}
|
}
|
||||||
smelted = true;
|
smelted = true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.secondSmeltTime = 0;
|
this.secondSmeltTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(smelted != this.lastSmelted){
|
if (smelted != this.lastSmelted) {
|
||||||
IBlockState currState = this.world.getBlockState(this.pos);
|
IBlockState currState = this.world.getBlockState(this.pos);
|
||||||
if(currState.getValue(BlockFurnaceDouble.IS_ON) != smelted){
|
if (currState.getValue(BlockFurnaceDouble.IS_ON) != smelted) {
|
||||||
this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, smelted));
|
this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, smelted));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastSmelted = smelted;
|
this.lastSmelted = smelted;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstSmelt != this.firstSmeltTime || this.lastSecondSmelt != this.secondSmeltTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()){
|
if ((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstSmelt != this.firstSmeltTime || this.lastSecondSmelt != this.secondSmeltTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
this.lastFirstSmelt = this.firstSmeltTime;
|
this.lastFirstSmelt = this.firstSmeltTime;
|
||||||
this.lastAutoSplit = this.isAutoSplit;
|
this.lastAutoSplit = this.isAutoSplit;
|
||||||
|
@ -159,58 +157,55 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || ((i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && StackUtil.isValid(FurnaceRecipes.instance().getSmeltingResult(stack)));
|
return (slot, stack, automation) -> !automation || ((slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2) && StackUtil.isValid(FurnaceRecipes.instance().getSmeltingResult(stack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canSmeltOn(int theInput, int theOutput){
|
@Override
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(theInput))){
|
public IRemover getRemover() {
|
||||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
|
return (slot, automation) -> !automation || (slot == SLOT_OUTPUT_1 || slot == SLOT_OUTPUT_2);
|
||||||
if(StackUtil.isValid(output)){
|
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || (this.inv.getStackInSlot(theOutput).isItemEqual(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize()-output.getCount())){
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canSmeltOn(int theInput, int theOutput) {
|
||||||
|
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
|
||||||
|
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
|
||||||
|
if (StackUtil.isValid(output)) {
|
||||||
|
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput)) || (this.inv.getStackInSlot(theOutput).isItemEqual(output) && this.inv.getStackInSlot(theOutput).getCount() <= this.inv.getStackInSlot(theOutput).getMaxStackSize() - output.getCount())) { return true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishBurning(int theInput, int theOutput){
|
public void finishBurning(int theInput, int theOutput) {
|
||||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
|
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.inv.getStackInSlot(theInput));
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(theOutput))){
|
if (!StackUtil.isValid(this.inv.getStackInSlot(theOutput))) {
|
||||||
this.inv.setStackInSlot(theOutput, output.copy());
|
this.inv.setStackInSlot(theOutput, output.copy());
|
||||||
}
|
} else if (this.inv.getStackInSlot(theOutput).getItem() == output.getItem()) {
|
||||||
else if(this.inv.getStackInSlot(theOutput).getItem() == output.getItem()){
|
|
||||||
this.inv.getStackInSlot(theOutput).grow(output.getCount());
|
this.inv.getStackInSlot(theOutput).grow(output.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inv.getStackInSlot(theInput).shrink(1);
|
this.inv.getStackInSlot(theInput).shrink(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFirstTimeToScale(int i){
|
public int getFirstTimeToScale(int i) {
|
||||||
return this.firstSmeltTime*i/SMELT_TIME;
|
return this.firstSmeltTime * i / SMELT_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSecondTimeToScale(int i){
|
public int getSecondTimeToScale(int i) {
|
||||||
return this.secondSmeltTime*i/SMELT_TIME;
|
return this.secondSmeltTime * i / SMELT_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
return !automation || (slot == SLOT_OUTPUT_1 || slot == SLOT_OUTPUT_2);
|
if (buttonID == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
|
||||||
if(buttonID == 0){
|
|
||||||
this.isAutoSplit = !this.isAutoSplit;
|
this.isAutoSplit = !this.isAutoSplit;
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
|
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
|
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -26,7 +27,7 @@ import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
public class TileEntityGrinder extends TileEntityInventoryBase implements IButtonReactor{
|
public class TileEntityGrinder extends TileEntityInventoryBase implements IButtonReactor {
|
||||||
|
|
||||||
public static final int SLOT_INPUT_1 = 0;
|
public static final int SLOT_INPUT_1 = 0;
|
||||||
public static final int SLOT_OUTPUT_1_1 = 1;
|
public static final int SLOT_OUTPUT_1_1 = 1;
|
||||||
|
@ -46,18 +47,18 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
|
||||||
private boolean lastAutoSplit;
|
private boolean lastAutoSplit;
|
||||||
private boolean lastCrushed;
|
private boolean lastCrushed;
|
||||||
|
|
||||||
public TileEntityGrinder(int slots, String name){
|
public TileEntityGrinder(int slots, String name) {
|
||||||
super(slots, name);
|
super(slots, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntityGrinder(){
|
public TileEntityGrinder() {
|
||||||
super(3, "grinder");
|
super(3, "grinder");
|
||||||
this.isDouble = false;
|
this.isDouble = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("FirstCrushTime", this.firstCrushTime);
|
compound.setInteger("FirstCrushTime", this.firstCrushTime);
|
||||||
compound.setInteger("SecondCrushTime", this.secondCrushTime);
|
compound.setInteger("SecondCrushTime", this.secondCrushTime);
|
||||||
compound.setBoolean("IsAutoSplit", this.isAutoSplit);
|
compound.setBoolean("IsAutoSplit", this.isAutoSplit);
|
||||||
|
@ -67,8 +68,8 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.firstCrushTime = compound.getInteger("FirstCrushTime");
|
this.firstCrushTime = compound.getInteger("FirstCrushTime");
|
||||||
this.secondCrushTime = compound.getInteger("SecondCrushTime");
|
this.secondCrushTime = compound.getInteger("SecondCrushTime");
|
||||||
this.isAutoSplit = compound.getBoolean("IsAutoSplit");
|
this.isAutoSplit = compound.getBoolean("IsAutoSplit");
|
||||||
|
@ -78,10 +79,10 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
if(this.isDouble && this.isAutoSplit){
|
if (this.isDouble && this.isAutoSplit) {
|
||||||
TileEntityFurnaceDouble.autoSplit(this.inv, SLOT_INPUT_1, SLOT_INPUT_2);
|
TileEntityFurnaceDouble.autoSplit(this.inv, SLOT_INPUT_1, SLOT_INPUT_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,129 +90,128 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
|
||||||
|
|
||||||
boolean canCrushOnFirst = this.canCrushOn(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2);
|
boolean canCrushOnFirst = this.canCrushOn(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2);
|
||||||
boolean canCrushOnSecond = false;
|
boolean canCrushOnSecond = false;
|
||||||
if(this.isDouble){
|
if (this.isDouble) {
|
||||||
canCrushOnSecond = this.canCrushOn(SLOT_INPUT_2, SLOT_OUTPUT_2_1, SLOT_OUTPUT_2_2);
|
canCrushOnSecond = this.canCrushOn(SLOT_INPUT_2, SLOT_OUTPUT_2_1, SLOT_OUTPUT_2_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean shouldPlaySound = false;
|
boolean shouldPlaySound = false;
|
||||||
|
|
||||||
if(canCrushOnFirst){
|
if (canCrushOnFirst) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
if(this.firstCrushTime%20 == 0){
|
if (this.firstCrushTime % 20 == 0) {
|
||||||
shouldPlaySound = true;
|
shouldPlaySound = true;
|
||||||
}
|
}
|
||||||
this.firstCrushTime++;
|
this.firstCrushTime++;
|
||||||
if(this.firstCrushTime >= this.getMaxCrushTime()){
|
if (this.firstCrushTime >= this.getMaxCrushTime()) {
|
||||||
this.finishCrushing(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2);
|
this.finishCrushing(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2);
|
||||||
this.firstCrushTime = 0;
|
this.firstCrushTime = 0;
|
||||||
}
|
}
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
}
|
}
|
||||||
crushed = storage.getEnergyStored() >= ENERGY_USE;
|
crushed = storage.getEnergyStored() >= ENERGY_USE;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.firstCrushTime = 0;
|
this.firstCrushTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.isDouble){
|
if (this.isDouble) {
|
||||||
if(canCrushOnSecond){
|
if (canCrushOnSecond) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
if(this.secondCrushTime%20 == 0){
|
if (this.secondCrushTime % 20 == 0) {
|
||||||
shouldPlaySound = true;
|
shouldPlaySound = true;
|
||||||
}
|
}
|
||||||
this.secondCrushTime++;
|
this.secondCrushTime++;
|
||||||
if(this.secondCrushTime >= this.getMaxCrushTime()){
|
if (this.secondCrushTime >= this.getMaxCrushTime()) {
|
||||||
this.finishCrushing(SLOT_INPUT_2, SLOT_OUTPUT_2_1, SLOT_OUTPUT_2_2);
|
this.finishCrushing(SLOT_INPUT_2, SLOT_OUTPUT_2_1, SLOT_OUTPUT_2_2);
|
||||||
this.secondCrushTime = 0;
|
this.secondCrushTime = 0;
|
||||||
}
|
}
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
}
|
}
|
||||||
crushed = storage.getEnergyStored() >= ENERGY_USE;
|
crushed = storage.getEnergyStored() >= ENERGY_USE;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.secondCrushTime = 0;
|
this.secondCrushTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(crushed != this.lastCrushed){
|
if (crushed != this.lastCrushed) {
|
||||||
IBlockState currState = this.world.getBlockState(this.pos);
|
IBlockState currState = this.world.getBlockState(this.pos);
|
||||||
if(currState.getValue(BlockFurnaceDouble.IS_ON) != crushed){
|
if (currState.getValue(BlockFurnaceDouble.IS_ON) != crushed) {
|
||||||
this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, crushed));
|
this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, crushed));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastCrushed = crushed;
|
this.lastCrushed = crushed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstCrush != this.firstCrushTime || this.lastSecondCrush != this.secondCrushTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()){
|
if ((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstCrush != this.firstCrushTime || this.lastSecondCrush != this.secondCrushTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
this.lastFirstCrush = this.firstCrushTime;
|
this.lastFirstCrush = this.firstCrushTime;
|
||||||
this.lastSecondCrush = this.secondCrushTime;
|
this.lastSecondCrush = this.secondCrushTime;
|
||||||
this.lastAutoSplit = this.isAutoSplit;
|
this.lastAutoSplit = this.isAutoSplit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shouldPlaySound){
|
if (shouldPlaySound) {
|
||||||
this.world.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.crusher, SoundCategory.BLOCKS, 0.025F, 1.0F);
|
this.world.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.crusher, SoundCategory.BLOCKS, 0.025F, 1.0F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || ((i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && CrusherRecipeRegistry.getRecipeFromInput(stack) != null);
|
return (slot, stack, automation) -> !automation || ((slot == SLOT_INPUT_1 || slot == SLOT_INPUT_2) && CrusherRecipeRegistry.getRecipeFromInput(stack) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){
|
@Override
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(theInput))){
|
public IRemover getRemover() {
|
||||||
|
return (slot, automation) -> !automation || (slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) {
|
||||||
|
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
|
||||||
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(inv.getStackInSlot(theInput));
|
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(inv.getStackInSlot(theInput));
|
||||||
if(recipe == null) return false;
|
if (recipe == null) return false;
|
||||||
ItemStack outputOne = recipe.getOutputOne();
|
ItemStack outputOne = recipe.getOutputOne();
|
||||||
ItemStack outputTwo = recipe.getOutputTwo();
|
ItemStack outputTwo = recipe.getOutputTwo();
|
||||||
if(StackUtil.isValid(outputOne)){
|
if (StackUtil.isValid(outputOne)) {
|
||||||
if(outputOne.getItemDamage() == Util.WILDCARD){
|
if (outputOne.getItemDamage() == Util.WILDCARD) {
|
||||||
outputOne.setItemDamage(0);
|
outputOne.setItemDamage(0);
|
||||||
}
|
}
|
||||||
if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){
|
if (StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD) {
|
||||||
outputTwo.setItemDamage(0);
|
outputTwo.setItemDamage(0);
|
||||||
}
|
}
|
||||||
if((!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput)) || (this.inv.getStackInSlot(theFirstOutput).isItemEqual(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize()-outputOne.getCount())) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput)) || (this.inv.getStackInSlot(theSecondOutput).isItemEqual(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize()-outputTwo.getCount())))){
|
if ((!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput)) || (this.inv.getStackInSlot(theFirstOutput).isItemEqual(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize() - outputOne.getCount())) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput)) || (this.inv.getStackInSlot(theSecondOutput).isItemEqual(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize() - outputTwo.getCount())))) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMaxCrushTime(){
|
private int getMaxCrushTime() {
|
||||||
return this.isDouble ? 150 : 100;
|
return this.isDouble ? 150 : 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){
|
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) {
|
||||||
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(inv.getStackInSlot(theInput));
|
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(inv.getStackInSlot(theInput));
|
||||||
if(recipe == null) return;
|
if (recipe == null) return;
|
||||||
ItemStack outputOne = recipe.getOutputOne();
|
ItemStack outputOne = recipe.getOutputOne();
|
||||||
if(StackUtil.isValid(outputOne)){
|
if (StackUtil.isValid(outputOne)) {
|
||||||
if(outputOne.getItemDamage() == Util.WILDCARD){
|
if (outputOne.getItemDamage() == Util.WILDCARD) {
|
||||||
outputOne.setItemDamage(0);
|
outputOne.setItemDamage(0);
|
||||||
}
|
}
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput))){
|
if (!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput))) {
|
||||||
this.inv.setStackInSlot(theFirstOutput, outputOne.copy());
|
this.inv.setStackInSlot(theFirstOutput, outputOne.copy());
|
||||||
}
|
} else if (this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()) {
|
||||||
else if(this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()){
|
|
||||||
this.inv.setStackInSlot(theFirstOutput, StackUtil.grow(this.inv.getStackInSlot(theFirstOutput), outputOne.getCount()));
|
this.inv.setStackInSlot(theFirstOutput, StackUtil.grow(this.inv.getStackInSlot(theFirstOutput), outputOne.getCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack outputTwo = recipe.getOutputTwo();
|
ItemStack outputTwo = recipe.getOutputTwo();
|
||||||
if(StackUtil.isValid(outputTwo)){
|
if (StackUtil.isValid(outputTwo)) {
|
||||||
if(outputTwo.getItemDamage() == Util.WILDCARD){
|
if (outputTwo.getItemDamage() == Util.WILDCARD) {
|
||||||
outputTwo.setItemDamage(0);
|
outputTwo.setItemDamage(0);
|
||||||
}
|
}
|
||||||
int rand = this.world.rand.nextInt(100)+1;
|
int rand = this.world.rand.nextInt(100) + 1;
|
||||||
if(rand <= recipe.getSecondChance()){
|
if (rand <= recipe.getSecondChance()) {
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))){
|
if (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))) {
|
||||||
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
||||||
}
|
} else if (this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()) {
|
||||||
else if(this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()){
|
|
||||||
this.inv.setStackInSlot(theSecondOutput, StackUtil.grow(this.inv.getStackInSlot(theSecondOutput), outputTwo.getCount()));
|
this.inv.setStackInSlot(theSecondOutput, StackUtil.grow(this.inv.getStackInSlot(theSecondOutput), outputTwo.getCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,33 +220,28 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
|
||||||
this.inv.getStackInSlot(theInput).shrink(1);
|
this.inv.getStackInSlot(theInput).shrink(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFirstTimeToScale(int i){
|
public int getFirstTimeToScale(int i) {
|
||||||
return this.firstCrushTime*i/this.getMaxCrushTime();
|
return this.firstCrushTime * i / this.getMaxCrushTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSecondTimeToScale(int i){
|
public int getSecondTimeToScale(int i) {
|
||||||
return this.secondCrushTime*i/this.getMaxCrushTime();
|
return this.secondCrushTime * i / this.getMaxCrushTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
return !automation || (slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2);
|
if (buttonID == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
|
||||||
if(buttonID == 0){
|
|
||||||
this.isAutoSplit = !this.isAutoSplit;
|
this.isAutoSplit = !this.isAutoSplit;
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,20 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.cyclops.commoncapabilities.capability.itemhandler.SlotlessItemHandlerConfig;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
|
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.tileentity.TileEntityFurnace;
|
import net.minecraft.tileentity.TileEntityFurnace;
|
||||||
|
@ -26,12 +31,8 @@ import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import org.cyclops.commoncapabilities.capability.itemhandler.SlotlessItemHandlerConfig;
|
|
||||||
|
|
||||||
import java.util.Map;
|
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor {
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor{
|
|
||||||
|
|
||||||
public static final int OKAY_BUTTON_ID = 133;
|
public static final int OKAY_BUTTON_ID = 133;
|
||||||
private final SlotlessableItemHandlerWrapper wrapper = new SlotlessableItemHandlerWrapper(this.inv, null);
|
private final SlotlessableItemHandlerWrapper wrapper = new SlotlessableItemHandlerWrapper(this.inv, null);
|
||||||
|
@ -53,54 +54,54 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
private int lastPullStart;
|
private int lastPullStart;
|
||||||
private int lastPullEnd;
|
private int lastPullEnd;
|
||||||
|
|
||||||
public TileEntityInputter(int slots, String name){
|
public TileEntityInputter(int slots, String name) {
|
||||||
super(slots, name);
|
super(slots, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntityInputter(){
|
public TileEntityInputter() {
|
||||||
super(1, "inputter");
|
super(1, "inputter");
|
||||||
this.isAdvanced = false;
|
this.isAdvanced = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNumberReceived(double number, int textID, EntityPlayer player){
|
public void onNumberReceived(double number, int textID, EntityPlayer player) {
|
||||||
int text = (int)number;
|
int text = (int) number;
|
||||||
|
|
||||||
if(text != -1){
|
if (text != -1) {
|
||||||
if(textID == 0){
|
if (textID == 0) {
|
||||||
this.slotToPutStart = Math.max(text, 0);
|
this.slotToPutStart = Math.max(text, 0);
|
||||||
}
|
}
|
||||||
if(textID == 1){
|
if (textID == 1) {
|
||||||
this.slotToPutEnd = Math.max(text, 0);
|
this.slotToPutEnd = Math.max(text, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(textID == 2){
|
if (textID == 2) {
|
||||||
this.slotToPullStart = Math.max(text, 0);
|
this.slotToPullStart = Math.max(text, 0);
|
||||||
}
|
}
|
||||||
if(textID == 3){
|
if (textID == 3) {
|
||||||
this.slotToPullEnd = Math.max(text, 0);
|
this.slotToPullEnd = Math.max(text, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean newPulling(){
|
private boolean newPulling() {
|
||||||
for(EnumFacing side : this.placeToPull.keySet()){
|
for (EnumFacing side : this.placeToPull.keySet()) {
|
||||||
WorldUtil.doItemInteraction(this.placeToPull.get(side), this.wrapper, Integer.MAX_VALUE, this.slotToPullStart, this.slotToPullEnd, 0, 1, !this.isAdvanced ? null : this.leftFilter);
|
WorldUtil.doItemInteraction(this.placeToPull.get(side), this.wrapper, Integer.MAX_VALUE, this.slotToPullStart, this.slotToPullEnd, 0, 1, !this.isAdvanced ? null : this.leftFilter);
|
||||||
|
|
||||||
if(this.placeToPull instanceof TileEntityItemViewer){
|
if (this.placeToPull instanceof TileEntityItemViewer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean newPutting(){
|
private boolean newPutting() {
|
||||||
if(!this.isAdvanced || this.rightFilter.check(this.inv.getStackInSlot(0))){
|
if (!this.isAdvanced || this.rightFilter.check(this.inv.getStackInSlot(0))) {
|
||||||
for(EnumFacing side : this.placeToPut.keySet()){
|
for (EnumFacing side : this.placeToPut.keySet()) {
|
||||||
WorldUtil.doItemInteraction(this.wrapper, this.placeToPut.get(side), Integer.MAX_VALUE, 0, 1, this.slotToPutStart, this.slotToPutEnd, null);
|
WorldUtil.doItemInteraction(this.wrapper, this.placeToPut.get(side), Integer.MAX_VALUE, 0, 1, this.slotToPutStart, this.slotToPutEnd, null);
|
||||||
|
|
||||||
if(this.placeToPut instanceof TileEntityItemViewer){
|
if (this.placeToPut instanceof TileEntityItemViewer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSaveDataOnChangeOrWorldStart(){
|
public boolean shouldSaveDataOnChangeOrWorldStart() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,29 +118,28 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
* Sets all of the relevant variables
|
* Sets all of the relevant variables
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
public void saveDataOnChangeOrWorldStart() {
|
||||||
this.placeToPull.clear();
|
this.placeToPull.clear();
|
||||||
this.placeToPut.clear();
|
this.placeToPut.clear();
|
||||||
|
|
||||||
if(this.sideToPull != -1){
|
if (this.sideToPull != -1) {
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
||||||
BlockPos offset = this.pos.offset(side);
|
BlockPos offset = this.pos.offset(side);
|
||||||
|
|
||||||
if(this.world.isBlockLoaded(offset)){
|
if (this.world.isBlockLoaded(offset)) {
|
||||||
TileEntity tile = this.world.getTileEntity(offset);
|
TileEntity tile = this.world.getTileEntity(offset);
|
||||||
|
|
||||||
if(tile != null){
|
if (tile != null) {
|
||||||
for(EnumFacing facing : EnumFacing.values()){
|
for (EnumFacing facing : EnumFacing.values()) {
|
||||||
IItemHandler normal = null;
|
IItemHandler normal = null;
|
||||||
if(tile.getClass() == TileEntityFurnace.class)
|
if (tile.getClass() == TileEntityFurnace.class) normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
else if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
|
||||||
else if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
|
|
||||||
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object slotless = null;
|
Object slotless = null;
|
||||||
if(ActuallyAdditions.commonCapsLoaded){
|
if (ActuallyAdditions.commonCapsLoaded) {
|
||||||
if(tile.hasCapability(SlotlessItemHandlerConfig.CAPABILITY, facing)){
|
if (tile.hasCapability(SlotlessItemHandlerConfig.CAPABILITY, facing)) {
|
||||||
slotless = tile.getCapability(SlotlessItemHandlerConfig.CAPABILITY, facing);
|
slotless = tile.getCapability(SlotlessItemHandlerConfig.CAPABILITY, facing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,10 +147,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
this.placeToPull.put(facing.getOpposite(), new SlotlessableItemHandlerWrapper(normal, slotless));
|
this.placeToPull.put(facing.getOpposite(), new SlotlessableItemHandlerWrapper(normal, slotless));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.slotToPullEnd <= 0){
|
if (this.slotToPullEnd <= 0) {
|
||||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
|
||||||
IItemHandler cap = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
IItemHandler cap = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
if(cap != null){
|
if (cap != null) {
|
||||||
this.slotToPullEnd = cap.getSlots();
|
this.slotToPullEnd = cap.getSlots();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,23 +159,23 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.sideToPut != -1){
|
if (this.sideToPut != -1) {
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
|
||||||
BlockPos offset = this.pos.offset(side);
|
BlockPos offset = this.pos.offset(side);
|
||||||
|
|
||||||
if(this.world.isBlockLoaded(offset)){
|
if (this.world.isBlockLoaded(offset)) {
|
||||||
TileEntity tile = this.world.getTileEntity(offset);
|
TileEntity tile = this.world.getTileEntity(offset);
|
||||||
|
|
||||||
if(tile != null){
|
if (tile != null) {
|
||||||
for(EnumFacing facing : EnumFacing.values()){
|
for (EnumFacing facing : EnumFacing.values()) {
|
||||||
IItemHandler normal = null;
|
IItemHandler normal = null;
|
||||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
|
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
|
||||||
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
normal = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object slotless = null;
|
Object slotless = null;
|
||||||
if(ActuallyAdditions.commonCapsLoaded){
|
if (ActuallyAdditions.commonCapsLoaded) {
|
||||||
if(tile.hasCapability(SlotlessItemHandlerConfig.CAPABILITY, facing)){
|
if (tile.hasCapability(SlotlessItemHandlerConfig.CAPABILITY, facing)) {
|
||||||
slotless = tile.getCapability(SlotlessItemHandlerConfig.CAPABILITY, facing);
|
slotless = tile.getCapability(SlotlessItemHandlerConfig.CAPABILITY, facing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,10 +183,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
this.placeToPut.put(facing.getOpposite(), new SlotlessableItemHandlerWrapper(normal, slotless));
|
this.placeToPut.put(facing.getOpposite(), new SlotlessableItemHandlerWrapper(normal, slotless));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.slotToPutEnd <= 0){
|
if (this.slotToPutEnd <= 0) {
|
||||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
|
||||||
IItemHandler cap = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
IItemHandler cap = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
if(cap != null){
|
if (cap != null) {
|
||||||
this.slotToPutEnd = cap.getSlots();
|
this.slotToPutEnd = cap.getSlots();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,44 +197,41 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
this.leftFilter.onButtonPressed(buttonID);
|
this.leftFilter.onButtonPressed(buttonID);
|
||||||
this.rightFilter.onButtonPressed(buttonID);
|
this.rightFilter.onButtonPressed(buttonID);
|
||||||
|
|
||||||
//Reset the Slots
|
//Reset the Slots
|
||||||
if(buttonID == 0 || buttonID == 1){
|
if (buttonID == 0 || buttonID == 1) {
|
||||||
this.slotToPutStart = 0;
|
this.slotToPutStart = 0;
|
||||||
this.slotToPutEnd = 0;
|
this.slotToPutEnd = 0;
|
||||||
}
|
}
|
||||||
if(buttonID == 2 || buttonID == 3){
|
if (buttonID == 2 || buttonID == 3) {
|
||||||
this.slotToPullStart = 0;
|
this.slotToPullStart = 0;
|
||||||
this.slotToPullEnd = 0;
|
this.slotToPullEnd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttonID == 0){
|
if (buttonID == 0) {
|
||||||
this.sideToPut++;
|
this.sideToPut++;
|
||||||
}
|
}
|
||||||
if(buttonID == 1){
|
if (buttonID == 1) {
|
||||||
this.sideToPut--;
|
this.sideToPut--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttonID == 2){
|
if (buttonID == 2) {
|
||||||
this.sideToPull++;
|
this.sideToPull++;
|
||||||
}
|
}
|
||||||
if(buttonID == 3){
|
if (buttonID == 3) {
|
||||||
this.sideToPull--;
|
this.sideToPull--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.sideToPut >= 6){
|
if (this.sideToPut >= 6) {
|
||||||
this.sideToPut = -1;
|
this.sideToPut = -1;
|
||||||
}
|
} else if (this.sideToPut < -1) {
|
||||||
else if(this.sideToPut < -1){
|
|
||||||
this.sideToPut = 5;
|
this.sideToPut = 5;
|
||||||
}
|
} else if (this.sideToPull >= 6) {
|
||||||
else if(this.sideToPull >= 6){
|
|
||||||
this.sideToPull = -1;
|
this.sideToPull = -1;
|
||||||
}
|
} else if (this.sideToPull < -1) {
|
||||||
else if(this.sideToPull < -1){
|
|
||||||
this.sideToPull = 5;
|
this.sideToPull = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +240,9 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("SideToPut", this.sideToPut);
|
compound.setInteger("SideToPut", this.sideToPut);
|
||||||
compound.setInteger("SlotToPut", this.slotToPutStart);
|
compound.setInteger("SlotToPut", this.slotToPutStart);
|
||||||
compound.setInteger("SlotToPutEnd", this.slotToPutEnd);
|
compound.setInteger("SlotToPutEnd", this.slotToPutEnd);
|
||||||
|
@ -259,8 +256,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.sideToPut = compound.getInteger("SideToPut");
|
this.sideToPut = compound.getInteger("SideToPut");
|
||||||
this.slotToPutStart = compound.getInteger("SlotToPut");
|
this.slotToPutStart = compound.getInteger("SlotToPut");
|
||||||
this.slotToPutEnd = compound.getInteger("SlotToPutEnd");
|
this.slotToPutEnd = compound.getInteger("SlotToPutEnd");
|
||||||
|
@ -276,19 +273,19 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
|
|
||||||
//Is Block not powered by Redstone?
|
//Is Block not powered by Redstone?
|
||||||
if(!this.isRedstonePowered){
|
if (!this.isRedstonePowered) {
|
||||||
if(this.ticksElapsed%30 == 0){
|
if (this.ticksElapsed % 30 == 0) {
|
||||||
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
|
if (!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)) {
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(0)) && this.sideToPull != -1 && this.placeToPull != null){
|
if (!StackUtil.isValid(this.inv.getStackInSlot(0)) && this.sideToPull != -1 && this.placeToPull != null) {
|
||||||
this.newPulling();
|
this.newPulling();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(0)) && this.sideToPut != -1 && this.placeToPut != null){
|
if (StackUtil.isValid(this.inv.getStackInSlot(0)) && this.sideToPut != -1 && this.placeToPut != null) {
|
||||||
this.newPutting();
|
this.newPutting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,7 +293,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update the Client
|
//Update the Client
|
||||||
if((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.leftFilter.needsUpdateSend() || this.rightFilter.needsUpdateSend()) && this.sendUpdateWithInterval()){
|
if ((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.leftFilter.needsUpdateSend() || this.rightFilter.needsUpdateSend()) && this.sendUpdateWithInterval()) {
|
||||||
this.lastPutSide = this.sideToPut;
|
this.lastPutSide = this.sideToPut;
|
||||||
this.lastPullSide = this.sideToPull;
|
this.lastPullSide = this.sideToPull;
|
||||||
this.lastPullStart = this.slotToPullStart;
|
this.lastPullStart = this.slotToPullStart;
|
||||||
|
@ -310,12 +307,12 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || i == 0;
|
return (slot, stack, automation) -> !automation || slot == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation || slot == 0;
|
return (slot, automation) -> !automation || slot == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,8 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -67,12 +69,12 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
|
||||||
return this.inv;
|
return this.inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean automation) {
|
public IAcceptor getAcceptor() {
|
||||||
return true;
|
return ItemStackHandlerAA.ACCEPT_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation) {
|
public IRemover getRemover() {
|
||||||
return true;
|
return ItemStackHandlerAA.REMOVE_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize(int slot) {
|
public int getMaxStackSize(int slot) {
|
||||||
|
@ -112,13 +114,13 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAccept(int slot, ItemStack stack, boolean fromAutomation) {
|
public IAcceptor getAcceptor() {
|
||||||
return TileEntityInventoryBase.this.canInsert(slot, stack, fromAutomation);
|
return TileEntityInventoryBase.this.getAcceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRemove(int slot, boolean byAutomation) {
|
public IRemover getRemover() {
|
||||||
return TileEntityInventoryBase.this.canExtract(slot, this.getStackInSlot(slot), byAutomation);
|
return TileEntityInventoryBase.this.getRemover();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -20,7 +22,7 @@ import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
public class TileEntityItemRepairer extends TileEntityInventoryBase {
|
||||||
|
|
||||||
public static final int SLOT_INPUT = 0;
|
public static final int SLOT_INPUT = 0;
|
||||||
public static final int SLOT_OUTPUT = 1;
|
public static final int SLOT_OUTPUT = 1;
|
||||||
|
@ -29,24 +31,21 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
||||||
public int nextRepairTick;
|
public int nextRepairTick;
|
||||||
private int lastEnergy;
|
private int lastEnergy;
|
||||||
|
|
||||||
public TileEntityItemRepairer(){
|
public TileEntityItemRepairer() {
|
||||||
super(2, "repairer");
|
super(2, "repairer");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canBeRepaired(ItemStack stack){
|
public static boolean canBeRepaired(ItemStack stack) {
|
||||||
if(StackUtil.isValid(stack)){
|
if (StackUtil.isValid(stack)) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if(item != null){
|
if (item != null) {
|
||||||
if(item.isRepairable() && item.getMaxDamage(stack) > 0){
|
if (item.isRepairable() && item.getMaxDamage(stack) > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
String reg = item.getRegistryName().toString();
|
String reg = item.getRegistryName().toString();
|
||||||
if(reg != null){
|
if (reg != null) {
|
||||||
for(String strg : ConfigStringListValues.REPAIRER_EXTRA_WHITELIST.getValue()){
|
for (String strg : ConfigStringListValues.REPAIRER_EXTRA_WHITELIST.getValue()) {
|
||||||
if(reg.equals(strg)){
|
if (reg.equals(strg)) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +55,8 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("NextRepairTick", this.nextRepairTick);
|
compound.setInteger("NextRepairTick", this.nextRepairTick);
|
||||||
}
|
}
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
|
@ -65,8 +64,8 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.nextRepairTick = compound.getInteger("NextRepairTick");
|
this.nextRepairTick = compound.getInteger("NextRepairTick");
|
||||||
}
|
}
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
|
@ -74,27 +73,26 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
ItemStack input = this.inv.getStackInSlot(SLOT_INPUT);
|
ItemStack input = this.inv.getStackInSlot(SLOT_INPUT);
|
||||||
if(!StackUtil.isValid(this.inv.getStackInSlot(SLOT_OUTPUT)) && canBeRepaired(input)){
|
if (!StackUtil.isValid(this.inv.getStackInSlot(SLOT_OUTPUT)) && canBeRepaired(input)) {
|
||||||
if(input.getItemDamage() <= 0){
|
if (input.getItemDamage() <= 0) {
|
||||||
this.inv.setStackInSlot(SLOT_OUTPUT, input.copy());
|
this.inv.setStackInSlot(SLOT_OUTPUT, input.copy());
|
||||||
this.inv.setStackInSlot(SLOT_INPUT, StackUtil.getEmpty());
|
this.inv.setStackInSlot(SLOT_INPUT, StackUtil.getEmpty());
|
||||||
this.nextRepairTick = 0;
|
this.nextRepairTick = 0;
|
||||||
}
|
} else {
|
||||||
else{
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
||||||
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
|
||||||
this.nextRepairTick++;
|
this.nextRepairTick++;
|
||||||
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
||||||
if(this.nextRepairTick >= 4){
|
if (this.nextRepairTick >= 4) {
|
||||||
this.nextRepairTick = 0;
|
this.nextRepairTick = 0;
|
||||||
input.setItemDamage(input.getItemDamage()-1);
|
input.setItemDamage(input.getItemDamage() - 1);
|
||||||
|
|
||||||
if(input.hasTagCompound()){
|
if (input.hasTagCompound()) {
|
||||||
//TiCon un-break tools
|
//TiCon un-break tools
|
||||||
if("tconstruct".equalsIgnoreCase(input.getItem().getRegistryName().getNamespace())){
|
if ("tconstruct".equalsIgnoreCase(input.getItem().getRegistryName().getNamespace())) {
|
||||||
NBTTagCompound stats = input.getTagCompound().getCompoundTag("Stats");
|
NBTTagCompound stats = input.getTagCompound().getCompoundTag("Stats");
|
||||||
stats.removeTag("Broken");
|
stats.removeTag("Broken");
|
||||||
}
|
}
|
||||||
|
@ -102,41 +100,38 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.nextRepairTick = 0;
|
this.nextRepairTick = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if (this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
||||||
this.lastEnergy = this.storage.getEnergyStored();
|
this.lastEnergy = this.storage.getEnergyStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || i == SLOT_INPUT;
|
return (slot, stack, automation) -> !automation || slot == SLOT_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getEnergyScaled(int i){
|
public int getEnergyScaled(int i) {
|
||||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getItemDamageToScale(int i){
|
public int getItemDamageToScale(int i) {
|
||||||
if(StackUtil.isValid(this.inv.getStackInSlot(SLOT_INPUT))){
|
if (StackUtil.isValid(this.inv.getStackInSlot(SLOT_INPUT))) { return (this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage() - this.inv.getStackInSlot(SLOT_INPUT).getItemDamage()) * i / this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage(); }
|
||||||
return (this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage()-this.inv.getStackInSlot(SLOT_INPUT).getItemDamage())*i/this.inv.getStackInSlot(SLOT_INPUT).getMaxDamage();
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation || slot == SLOT_OUTPUT;
|
return (slot, automation) -> !automation || slot == SLOT_OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
||||||
return this.storage;
|
return this.storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
|
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -195,13 +196,8 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation) {
|
public IAcceptor getAcceptor() {
|
||||||
return !fromAutomation;
|
return (stack, slot, automation) -> !automation;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,11 +10,25 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
public class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
|
|
||||||
public TileEntityPhantomBreaker(){
|
public class TileEntityPhantomBreaker extends TileEntityPhantomPlacer {
|
||||||
|
|
||||||
|
public TileEntityPhantomBreaker() {
|
||||||
super(9, "phantomBreaker");
|
super(9, "phantomBreaker");
|
||||||
this.isBreaker = true;
|
this.isBreaker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAcceptor getAcceptor() {
|
||||||
|
return ItemStackHandlerAA.ACCEPT_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IRemover getRemover() {
|
||||||
|
return ItemStackHandlerAA.REMOVE_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,33 +11,32 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
||||||
import net.minecraft.item.ItemStack;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
|
||||||
public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
public class TileEntityPhantomItemface extends TileEntityPhantomface {
|
||||||
|
|
||||||
public TileEntityPhantomItemface(){
|
public TileEntityPhantomItemface() {
|
||||||
super("phantomface");
|
super("phantomface");
|
||||||
this.type = BlockPhantom.Type.FACE;
|
this.type = BlockPhantom.Type.FACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || this.isBoundThingInRange();
|
return (slot, stack, automation) -> !automation || this.isBoundThingInRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBoundThingInRange(){
|
public boolean isBoundThingInRange() {
|
||||||
if(super.isBoundThingInRange()){
|
if (super.isBoundThingInRange()) {
|
||||||
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
||||||
if(tile != null){
|
if (tile != null) {
|
||||||
for(EnumFacing facing : EnumFacing.values()){
|
for (EnumFacing facing : EnumFacing.values()) {
|
||||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
|
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +44,12 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isCapabilitySupported(Capability<?> capability){
|
protected boolean isCapabilitySupported(Capability<?> capability) {
|
||||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation || this.isBoundThingInRange();
|
return (slot, automation) -> !automation || this.isBoundThingInRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,9 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
|
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -24,7 +27,7 @@ import net.minecraft.util.EnumParticleTypes;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile, IButtonReactor{
|
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile, IButtonReactor {
|
||||||
|
|
||||||
public static final int RANGE = 3;
|
public static final int RANGE = 3;
|
||||||
public BlockPos boundPosition;
|
public BlockPos boundPosition;
|
||||||
|
@ -34,90 +37,88 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
||||||
public int side;
|
public int side;
|
||||||
private int oldRange;
|
private int oldRange;
|
||||||
|
|
||||||
public TileEntityPhantomPlacer(int slots, String name){
|
public TileEntityPhantomPlacer(int slots, String name) {
|
||||||
super(slots, name);
|
super(slots, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntityPhantomPlacer(){
|
public TileEntityPhantomPlacer() {
|
||||||
super(9, "phantomPlacer");
|
super(9, "phantomPlacer");
|
||||||
this.isBreaker = false;
|
this.isBreaker = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("Range", this.range);
|
compound.setInteger("Range", this.range);
|
||||||
if(this.boundPosition != null){
|
if (this.boundPosition != null) {
|
||||||
compound.setInteger("xOfTileStored", this.boundPosition.getX());
|
compound.setInteger("xOfTileStored", this.boundPosition.getX());
|
||||||
compound.setInteger("yOfTileStored", this.boundPosition.getY());
|
compound.setInteger("yOfTileStored", this.boundPosition.getY());
|
||||||
compound.setInteger("zOfTileStored", this.boundPosition.getZ());
|
compound.setInteger("zOfTileStored", this.boundPosition.getZ());
|
||||||
}
|
}
|
||||||
if(!this.isBreaker){
|
if (!this.isBreaker) {
|
||||||
compound.setInteger("Side", this.side);
|
compound.setInteger("Side", this.side);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
int x = compound.getInteger("xOfTileStored");
|
int x = compound.getInteger("xOfTileStored");
|
||||||
int y = compound.getInteger("yOfTileStored");
|
int y = compound.getInteger("yOfTileStored");
|
||||||
int z = compound.getInteger("zOfTileStored");
|
int z = compound.getInteger("zOfTileStored");
|
||||||
this.range = compound.getInteger("Range");
|
this.range = compound.getInteger("Range");
|
||||||
if(!(x == 0 && y == 0 && z == 0)){
|
if (!(x == 0 && y == 0 && z == 0)) {
|
||||||
this.boundPosition = new BlockPos(x, y, z);
|
this.boundPosition = new BlockPos(x, y, z);
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
if(!this.isBreaker){
|
if (!this.isBreaker) {
|
||||||
this.side = compound.getInteger("Side");
|
this.side = compound.getInteger("Side");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity(){
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if (!this.world.isRemote) {
|
||||||
this.range = TileEntityPhantomface.upgradeRange(RANGE, this.world, this.pos);
|
this.range = TileEntityPhantomface.upgradeRange(RANGE, this.world, this.pos);
|
||||||
|
|
||||||
if(!this.hasBoundPosition()){
|
if (!this.hasBoundPosition()) {
|
||||||
this.boundPosition = null;
|
this.boundPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.isBoundThingInRange()){
|
if (this.isBoundThingInRange()) {
|
||||||
if(!this.isRedstonePowered && !this.isPulseMode){
|
if (!this.isRedstonePowered && !this.isPulseMode) {
|
||||||
if(this.currentTime > 0){
|
if (this.currentTime > 0) {
|
||||||
this.currentTime--;
|
this.currentTime--;
|
||||||
if(this.currentTime <= 0){
|
if (this.currentTime <= 0) {
|
||||||
this.doWork();
|
this.doWork();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.currentTime = 30;
|
this.currentTime = 30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.oldRange != this.range){
|
if (this.oldRange != this.range) {
|
||||||
this.oldRange = this.range;
|
this.oldRange = this.range;
|
||||||
|
|
||||||
this.sendUpdate();
|
this.sendUpdate();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
if (this.boundPosition != null) {
|
||||||
if(this.boundPosition != null){
|
|
||||||
this.renderParticles();
|
this.renderParticles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasBoundPosition(){
|
public boolean hasBoundPosition() {
|
||||||
if(this.boundPosition != null){
|
if (this.boundPosition != null) {
|
||||||
if(this.world.getTileEntity(this.boundPosition) instanceof IPhantomTile || (this.getPos().getX() == this.boundPosition.getX() && this.getPos().getY() == this.boundPosition.getY() && this.getPos().getZ() == this.boundPosition.getZ() && this.world.provider.getDimension() == this.world.provider.getDimension())){
|
if (this.world.getTileEntity(this.boundPosition) instanceof IPhantomTile || (this.getPos().getX() == this.boundPosition.getX() && this.getPos().getY() == this.boundPosition.getY() && this.getPos().getZ() == this.boundPosition.getZ() && this.world.provider.getDimension() == this.world.provider.getDimension())) {
|
||||||
this.boundPosition = null;
|
this.boundPosition = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -126,95 +127,93 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWork(){
|
private void doWork() {
|
||||||
if(this.isBoundThingInRange()){
|
if (this.isBoundThingInRange()) {
|
||||||
if(this.isBreaker){
|
if (this.isBreaker) {
|
||||||
Block blockToBreak = this.world.getBlockState(this.boundPosition).getBlock();
|
Block blockToBreak = this.world.getBlockState(this.boundPosition).getBlock();
|
||||||
if(blockToBreak != null && this.world.getBlockState(this.boundPosition).getBlockHardness(this.world, this.boundPosition) > -1.0F){
|
if (blockToBreak != null && this.world.getBlockState(this.boundPosition).getBlockHardness(this.world, this.boundPosition) > -1.0F) {
|
||||||
NonNullList<ItemStack> drops = NonNullList.create();
|
NonNullList<ItemStack> drops = NonNullList.create();
|
||||||
blockToBreak.getDrops(drops, world, pos, this.world.getBlockState(this.boundPosition), 0);
|
blockToBreak.getDrops(drops, world, pos, this.world.getBlockState(this.boundPosition), 0);
|
||||||
|
|
||||||
if(StackUtil.canAddAll(this.inv, drops, false)){
|
if (StackUtil.canAddAll(this.inv, drops, false)) {
|
||||||
this.world.playEvent(2001, this.boundPosition, Block.getStateId(this.world.getBlockState(this.boundPosition)));
|
this.world.playEvent(2001, this.boundPosition, Block.getStateId(this.world.getBlockState(this.boundPosition)));
|
||||||
this.world.setBlockToAir(this.boundPosition);
|
this.world.setBlockToAir(this.boundPosition);
|
||||||
StackUtil.addAll(this.inv, drops, false);
|
StackUtil.addAll(this.inv, drops, false);
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
int theSlot = StackUtil.findFirstFilled(this.inv);
|
int theSlot = StackUtil.findFirstFilled(this.inv);
|
||||||
if(theSlot == -1) return;
|
if (theSlot == -1) return;
|
||||||
inv.setStackInSlot(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, inv.getStackInSlot(theSlot)));
|
inv.setStackInSlot(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, inv.getStackInSlot(theSlot)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderParticles(){
|
public void renderParticles() {
|
||||||
if(this.world.rand.nextInt(2) == 0){
|
if (this.world.rand.nextInt(2) == 0) {
|
||||||
double d1 = (double)((float)this.boundPosition.getY()+this.world.rand.nextFloat());
|
double d1 = (double) ((float) this.boundPosition.getY() + this.world.rand.nextFloat());
|
||||||
int i1 = this.world.rand.nextInt(2)*2-1;
|
int i1 = this.world.rand.nextInt(2) * 2 - 1;
|
||||||
int j1 = this.world.rand.nextInt(2)*2-1;
|
int j1 = this.world.rand.nextInt(2) * 2 - 1;
|
||||||
double d4 = ((double)this.world.rand.nextFloat()-0.5D)*0.125D;
|
double d4 = ((double) this.world.rand.nextFloat() - 0.5D) * 0.125D;
|
||||||
double d2 = (double)this.boundPosition.getZ()+0.5D+0.25D*(double)j1;
|
double d2 = (double) this.boundPosition.getZ() + 0.5D + 0.25D * (double) j1;
|
||||||
double d5 = (double)(this.world.rand.nextFloat()*1.0F*(float)j1);
|
double d5 = (double) (this.world.rand.nextFloat() * 1.0F * (float) j1);
|
||||||
double d0 = (double)this.boundPosition.getX()+0.5D+0.25D*(double)i1;
|
double d0 = (double) this.boundPosition.getX() + 0.5D + 0.25D * (double) i1;
|
||||||
double d3 = (double)(this.world.rand.nextFloat()*1.0F*(float)i1);
|
double d3 = (double) (this.world.rand.nextFloat() * 1.0F * (float) i1);
|
||||||
this.world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
|
this.world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBoundThingInRange(){
|
public boolean isBoundThingInRange() {
|
||||||
return this.hasBoundPosition() && this.boundPosition.distanceSq(this.pos) <= this.range*this.range;
|
return this.hasBoundPosition() && this.boundPosition.distanceSq(this.pos) <= this.range * this.range;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos getBoundPosition(){
|
public BlockPos getBoundPosition() {
|
||||||
return this.boundPosition;
|
return this.boundPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBoundPosition(BlockPos pos){
|
public void setBoundPosition(BlockPos pos) {
|
||||||
this.boundPosition = pos;
|
this.boundPosition = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGuiID(){
|
public int getGuiID() {
|
||||||
return GuiHandler.GuiTypes.PHANTOM_PLACER.ordinal();
|
return GuiHandler.GuiTypes.PHANTOM_PLACER.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRange(){
|
public int getRange() {
|
||||||
return this.range;
|
return this.range;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean automation){
|
public IAcceptor getAcceptor() {
|
||||||
return !automation || !this.isBreaker;
|
return ItemStackHandlerAA.ACCEPT_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean automation){
|
public IRemover getRemover() {
|
||||||
return !automation || this.isBreaker;
|
return ItemStackHandlerAA.REMOVE_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRedstoneToggle(){
|
public boolean isRedstoneToggle() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activateOnPulse(){
|
public void activateOnPulse() {
|
||||||
this.doWork();
|
this.doWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
public void onButtonPressed(int buttonID, EntityPlayer player) {
|
||||||
if(this.side+1 >= EnumFacing.values().length){
|
if (this.side + 1 >= EnumFacing.values().length) {
|
||||||
this.side = 0;
|
this.side = 0;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.side++;
|
this.side++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,19 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
public class TileEntityPlacer extends TileEntityBreaker{
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
|
|
||||||
public TileEntityPlacer(){
|
public class TileEntityPlacer extends TileEntityBreaker {
|
||||||
|
|
||||||
|
public TileEntityPlacer() {
|
||||||
super(9, "placer");
|
super(9, "placer");
|
||||||
this.isPlacer = true;
|
this.isPlacer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAcceptor getAcceptor() {
|
||||||
|
return ItemStackHandlerAA.ACCEPT_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -87,13 +88,8 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int i, ItemStack stack, boolean fromAutomation) {
|
public IAcceptor getAcceptor() {
|
||||||
return !fromAutomation;
|
return (slot, stack, automation) -> !automation;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ItemSolidifiedExperience;
|
import de.ellpeck.actuallyadditions.mod.items.ItemSolidifiedExperience;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.entity.item.EntityXPOrb;
|
import net.minecraft.entity.item.EntityXPOrb;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -22,8 +25,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TileEntityXPSolidifier extends TileEntityInventoryBase implements IButtonReactor {
|
public class TileEntityXPSolidifier extends TileEntityInventoryBase implements IButtonReactor {
|
||||||
|
|
||||||
private static final int[] XP_MAP = new int[256];
|
private static final int[] XP_MAP = new int[256];
|
||||||
|
@ -162,13 +163,8 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int slot, ItemStack stack, boolean fromAutomation) {
|
public IAcceptor getAcceptor() {
|
||||||
return slot == 1 && stack.getItem() == InitItems.itemSolidifiedExperience;
|
return (slot, stack, automation) -> slot == 1 && stack.getItem() == InitItems.itemSolidifiedExperience;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExtract(int slot, ItemStack stack, boolean byAutomation) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -104,6 +104,7 @@ public final class AwfulUtil{
|
||||||
error += ("\n" + i++ + ": " + (k == null ? "null" : (k.getClass().getSimpleName() + " <- CLASS | INSTANCE -> " + k.toString() + ", ")));
|
error += ("\n" + i++ + ": " + (k == null ? "null" : (k.getClass().getSimpleName() + " <- CLASS | INSTANCE -> " + k.toString() + ", ")));
|
||||||
}
|
}
|
||||||
error += "\n" + "The current side is: " + FMLCommonHandler.instance().getEffectiveSide();
|
error += "\n" + "The current side is: " + FMLCommonHandler.instance().getEffectiveSide();
|
||||||
|
error += "\n" + "Report this to https://github.com/Ellpeck/ActuallyAdditions/issues";
|
||||||
throw new IllegalStateException(error);
|
throw new IllegalStateException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,32 @@ import net.minecraftforge.items.ItemStackHandler;
|
||||||
*/
|
*/
|
||||||
public class ItemStackHandlerAA extends ItemStackHandler {
|
public class ItemStackHandlerAA extends ItemStackHandler {
|
||||||
|
|
||||||
public ItemStackHandlerAA(int slots) {
|
public static final IAcceptor ACCEPT_TRUE = (a, b, c) -> true;
|
||||||
|
public static final IRemover REMOVE_TRUE = (a, b) -> true;
|
||||||
|
public static final IAcceptor ACCEPT_FALSE = (a, b, c) -> false;
|
||||||
|
public static final IRemover REMOVE_FALSE = (a, b) -> false;
|
||||||
|
|
||||||
|
IAcceptor acceptor;
|
||||||
|
IRemover remover;
|
||||||
|
|
||||||
|
public ItemStackHandlerAA(NonNullList<ItemStack> stacks, IAcceptor acceptor, IRemover remover) {
|
||||||
|
super(stacks);
|
||||||
|
this.acceptor = acceptor;
|
||||||
|
this.remover = remover;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackHandlerAA(int slots, IAcceptor acceptor, IRemover remover) {
|
||||||
super(slots);
|
super(slots);
|
||||||
|
this.acceptor = acceptor;
|
||||||
|
this.remover = remover;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackHandlerAA(NonNullList<ItemStack> stacks) {
|
||||||
|
this(stacks, ACCEPT_TRUE, REMOVE_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackHandlerAA(int slots) {
|
||||||
|
this(slots, ACCEPT_TRUE, REMOVE_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NonNullList<ItemStack> getItems() {
|
public NonNullList<ItemStack> getItems() {
|
||||||
|
@ -48,11 +72,33 @@ public class ItemStackHandlerAA extends ItemStackHandler {
|
||||||
return super.extractItem(slot, amount, simulate);
|
return super.extractItem(slot, amount, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canAccept(int slot, ItemStack stack, boolean fromAutomation) {
|
public final boolean canAccept(int slot, ItemStack stack, boolean automation) {
|
||||||
return true;
|
IAcceptor acceptor = getAcceptor();
|
||||||
|
try {
|
||||||
|
return acceptor.canAccept(slot, stack, automation);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRemove(int slot, boolean byAutomation) {
|
public final boolean canRemove(int slot, boolean automation) {
|
||||||
return true;
|
return getRemover().canRemove(slot, automation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAcceptor getAcceptor() {
|
||||||
|
return acceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRemover getRemover() {
|
||||||
|
return remover;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface IAcceptor {
|
||||||
|
boolean canAccept(int slot, ItemStack stack, boolean automation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface IRemover {
|
||||||
|
boolean canRemove(int slot, boolean automation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.util;
|
package de.ellpeck.actuallyadditions.mod.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -23,7 +22,6 @@ import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
|
|
||||||
public final class StackUtil {
|
public final class StackUtil {
|
||||||
|
|
||||||
|
@ -67,42 +65,6 @@ public final class StackUtil {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if all provided itemstacks will fit in the handler. If you have an AA item handler, use the more sensitive below methods.
|
|
||||||
* @param inv The Item handler
|
|
||||||
* @param stacks The stacks to add
|
|
||||||
* @return If all stacks fit fully. If even one item would not fit, the method returns false.
|
|
||||||
*/
|
|
||||||
public static boolean canAddAll(IItemHandler inv, List<ItemStack> stacks) {
|
|
||||||
|
|
||||||
int slotMax = inv.getSlots();
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
for (ItemStack s : stacks = merge(stacks)) {
|
|
||||||
for (int i = 0; i < slotMax; i++) {
|
|
||||||
s = inv.insertItem(i, s, true);
|
|
||||||
if (s.isEmpty()) break;
|
|
||||||
}
|
|
||||||
if (s.isEmpty()) counter++;
|
|
||||||
}
|
|
||||||
return counter == stacks.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds all itemstacks in a list to an item handler. If you have an AA item handler, use the more sensitive below methods.
|
|
||||||
* @param inv The Item handler
|
|
||||||
* @param stacks The stacks to add
|
|
||||||
*/
|
|
||||||
public static void addAll(IItemHandler inv, List<ItemStack> stacks) {
|
|
||||||
int slotMax = inv.getSlots();
|
|
||||||
for (ItemStack s : stacks) {
|
|
||||||
for (int i = 0; i < slotMax; i++) {
|
|
||||||
s = inv.insertItem(i, s, false);
|
|
||||||
if (s.isEmpty()) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if all provided itemstacks will fit in the AA handler. Use addAll below to actually add the stacks. This is strictly a check function.
|
* Checks if all provided itemstacks will fit in the AA handler. Use addAll below to actually add the stacks. This is strictly a check function.
|
||||||
* @param inv The AA Item handler
|
* @param inv The AA Item handler
|
||||||
|
@ -111,13 +73,11 @@ public final class StackUtil {
|
||||||
* @return If all stacks fit fully. If even one item would not fit, the method returns false.
|
* @return If all stacks fit fully. If even one item would not fit, the method returns false.
|
||||||
*/
|
*/
|
||||||
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, boolean fromAutomation) {
|
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, boolean fromAutomation) {
|
||||||
|
|
||||||
int slotMax = inv.getSlots();
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
ItemStackHandlerAA dummy = testDummy(inv, 0, inv.getSlots());
|
||||||
for (ItemStack s : stacks = merge(stacks)) {
|
for (ItemStack s : stacks) {
|
||||||
for (int i = 0; i < slotMax; i++) {
|
for (int i = 0; i < dummy.getSlots(); i++) {
|
||||||
s = inv.insertItem(i, s, true, fromAutomation);
|
s = dummy.insertItem(i, s, false, fromAutomation);
|
||||||
if (s.isEmpty()) break;
|
if (s.isEmpty()) break;
|
||||||
}
|
}
|
||||||
if (s.isEmpty()) counter++;
|
if (s.isEmpty()) counter++;
|
||||||
|
@ -152,10 +112,10 @@ public final class StackUtil {
|
||||||
*/
|
*/
|
||||||
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, int slot, int endSlot, boolean fromAutomation) {
|
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, int slot, int endSlot, boolean fromAutomation) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
ItemStackHandlerAA dummy = testDummy(inv, slot, endSlot);
|
||||||
for (ItemStack s : stacks = merge(stacks)) {
|
for (ItemStack s : stacks) {
|
||||||
for (int i = slot; i < endSlot; i++) {
|
for (int i = 0; i < dummy.getSlots(); i++) {
|
||||||
s = inv.insertItem(i, s, true, fromAutomation);
|
s = dummy.insertItem(i, s, false, fromAutomation);
|
||||||
if (s.isEmpty()) break;
|
if (s.isEmpty()) break;
|
||||||
}
|
}
|
||||||
if (s.isEmpty()) counter++;
|
if (s.isEmpty()) counter++;
|
||||||
|
@ -249,31 +209,14 @@ public final class StackUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines every stack in the given list into larger stacks when possible.
|
* Constructs a clone of the given item handler, from the given slots. The new item handler will have the provided slot as slot 0.
|
||||||
|
* This is used for testing the ability to add all itemstacks, and should not be used for anything else.
|
||||||
*/
|
*/
|
||||||
public static List<ItemStack> merge(List<ItemStack> stacks) {
|
public static ItemStackHandlerAA testDummy(ItemStackHandlerAA inv, int slot, int endSlot) {
|
||||||
if (stacks.isEmpty()) return stacks;
|
NonNullList<ItemStack> stacks = NonNullList.withSize(endSlot - slot, getEmpty());
|
||||||
|
for (int i = slot; i < endSlot; i++)
|
||||||
ItemStack[] array = stacks.toArray(new ItemStack[0]);
|
stacks.set(i - slot, inv.getStackInSlot(i).copy());
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return new ItemStackHandlerAA(stacks, inv.getAcceptor(), inv.getRemover());
|
||||||
|
|
||||||
while (!array[array.length - 1].isEmpty()) {
|
|
||||||
ItemStack merged = ItemStack.EMPTY;
|
|
||||||
for (int i = 0; i < array.length; i++) {
|
|
||||||
ItemStack stack = array[i];
|
|
||||||
if (merged.isEmpty()) {
|
|
||||||
merged = stack.copy();
|
|
||||||
array[i] = ItemStack.EMPTY;
|
|
||||||
} else if (ItemHandlerHelper.canItemStacksStack(merged, stack)) {
|
|
||||||
merged.grow(stack.getCount());
|
|
||||||
array[i] = ItemStack.EMPTY;
|
|
||||||
} else break;
|
|
||||||
}
|
|
||||||
list.add(merged);
|
|
||||||
merged = ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue