2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-04-28 00:51:06 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-03-13 19:49:28 +01:00
|
|
|
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.ItemUtils;
|
2017-03-13 19:49:28 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2017-03-13 11:22:06 +01:00
|
|
|
import techreborn.init.IC2Duplicates;
|
2015-04-28 00:51:06 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-06-22 12:32:30 +02:00
|
|
|
import techreborn.init.ModItems;
|
2016-03-27 19:56:27 +02:00
|
|
|
import techreborn.items.ItemParts;
|
2015-06-22 12:32:30 +02:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public class TileMatterFabricator extends TilePowerAcceptor
|
2017-04-08 16:03:46 +02:00
|
|
|
implements IWrenchable, IInventoryProvider, IContainerProvider {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-03-13 11:22:06 +01:00
|
|
|
public int fabricationRate = 10000;
|
2016-03-25 10:47:34 +01:00
|
|
|
public int tickTime;
|
2017-05-23 14:28:35 +02:00
|
|
|
public Inventory inventory = new Inventory(11, "TileMatterFabricator", 64, this);
|
2016-03-25 10:47:34 +01:00
|
|
|
private int amplifier = 0;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileMatterFabricator() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(6);
|
|
|
|
// TODO configs
|
|
|
|
}
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
2017-01-08 15:22:59 +01:00
|
|
|
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2017-01-08 15:22:59 +01:00
|
|
|
return this.getFacingEnum();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 15:22:59 +01:00
|
|
|
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public float getWrenchDropRate() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 15:22:59 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.MATTER_FABRICATOR, 1);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isComplete() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-08 16:03:46 +02:00
|
|
|
@Override
|
|
|
|
public int[] getSlotsForFace(EnumFacing side) {
|
|
|
|
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5, 6 } : new int[] { 0, 1, 2, 3, 4, 5, 6 };
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
|
|
|
if (slotIndex == 6)
|
|
|
|
return false;
|
|
|
|
return isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
|
2017-04-08 16:03:46 +02:00
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
|
|
|
return slotIndex == 6;
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
|
|
|
|
2016-11-19 13:50:08 +01:00
|
|
|
if (!super.world.isRemote) {
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2017-01-08 15:22:59 +01:00
|
|
|
final ItemStack stack = this.inventory.getStackInSlot(i);
|
2017-04-14 18:56:11 +02:00
|
|
|
if (!stack.isEmpty() && spaceForOutput()) {
|
2017-03-13 11:22:06 +01:00
|
|
|
final int amp = this.getValue(stack);
|
2017-04-08 16:03:46 +02:00
|
|
|
if (amp != 0 && this.canUseEnergy(85)) {
|
2017-03-13 11:22:06 +01:00
|
|
|
this.useEnergy(85);
|
|
|
|
this.amplifier += amp;
|
|
|
|
this.inventory.decrStackSize(i, 1);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 16:03:46 +02:00
|
|
|
if (amplifier >= fabricationRate) {
|
|
|
|
if (spaceForOutput()) {
|
2017-03-13 11:22:06 +01:00
|
|
|
this.addOutputProducts();
|
|
|
|
amplifier -= fabricationRate;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private boolean spaceForOutput() {
|
2017-06-02 21:36:02 +02:00
|
|
|
for (int i = 6; i < 11; i++) {
|
2017-05-23 14:28:35 +02:00
|
|
|
if(spaceForOutput(i)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean spaceForOutput(int slot) {
|
2017-06-02 21:20:56 +02:00
|
|
|
return this.inventory.getStackInSlot(slot).isEmpty()
|
2017-05-23 14:28:35 +02:00
|
|
|
|| ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true)
|
2017-06-02 21:20:56 +02:00
|
|
|
&& this.inventory.getStackInSlot(slot).getCount() < 64;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private void addOutputProducts() {
|
2017-06-02 21:36:02 +02:00
|
|
|
for (int i = 6; i < 11; i++) {
|
2017-05-23 14:28:35 +02:00
|
|
|
if(spaceForOutput(i)){
|
|
|
|
addOutputProducts(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addOutputProducts(int slot) {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-02 21:20:56 +02:00
|
|
|
if (this.inventory.getStackInSlot(slot).isEmpty()) {
|
2017-05-23 14:28:35 +02:00
|
|
|
this.inventory.setInventorySlotContents(slot, new ItemStack(ModItems.UU_MATTER));
|
|
|
|
} else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true)) {
|
2017-06-02 21:20:56 +02:00
|
|
|
this.inventory.getStackInSlot(slot).setCount((Math.min(64, 1 + this.inventory.getStackInSlot(slot).getCount())));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 15:22:59 +01:00
|
|
|
public boolean decreaseStoredEnergy(final double aEnergy, final boolean aIgnoreTooLessEnergy) {
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2017-01-08 15:22:59 +01:00
|
|
|
this.setEnergy(this.getEnergy() - aEnergy);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.getEnergy() < 0) {
|
2017-01-08 15:22:59 +01:00
|
|
|
this.setEnergy(0);
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 11:22:06 +01:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 15:22:59 +01:00
|
|
|
public int getValue(final ItemStack itemStack) {
|
2017-01-01 08:29:32 +01:00
|
|
|
if (itemStack.getItem() == ModItems.PARTS && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) {
|
2017-03-13 11:22:06 +01:00
|
|
|
return 200;
|
2017-01-01 08:29:32 +01:00
|
|
|
} else if (itemStack.getItem() == ModItems.SCRAP_BOX) {
|
2017-03-13 11:22:06 +01:00
|
|
|
return 2000;
|
|
|
|
}
|
2017-04-08 16:03:46 +02:00
|
|
|
if (IC2Duplicates.SCRAP.hasIC2Stack()) {
|
|
|
|
if (ItemUtils.isInputEqual(itemStack, IC2Duplicates.SCRAP.getIc2Stack(), true, true, true)) {
|
2017-03-13 11:22:06 +01:00
|
|
|
return 200;
|
|
|
|
}
|
2016-03-27 19:56:27 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 100000000;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
2017-01-08 15:22:59 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
2017-01-08 15:22:59 +01:00
|
|
|
public boolean canProvideEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 4096;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public EnumPowerTier getBaseTier() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return EnumPowerTier.EXTREME;
|
|
|
|
}
|
2016-04-11 18:43:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
2017-01-08 15:22:59 +01:00
|
|
|
return this.inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getProgress() {
|
2017-03-13 11:22:06 +01:00
|
|
|
return this.amplifier;
|
2017-01-08 15:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setProgress(final int progress) {
|
2017-03-13 11:22:06 +01:00
|
|
|
this.amplifier = progress;
|
2017-01-08 15:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getProgressScaled(final int scale) {
|
2017-03-13 11:22:06 +01:00
|
|
|
if (this.amplifier != 0) {
|
|
|
|
return Math.min(this.amplifier * scale / fabricationRate, 100);
|
2017-01-08 15:22:59 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2016-04-11 18:43:54 +02:00
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
2017-05-23 14:28:35 +02:00
|
|
|
return new ContainerBuilder("matterfabricator").player(player.inventory).inventory().hotbar()
|
|
|
|
.addInventory().tile(this).slot(0, 30, 20).slot(1, 50, 20).slot(2, 70, 20).slot(3, 90, 20)
|
|
|
|
.slot(4, 110, 20).slot(5, 130, 20).outputSlot(6, 40, 66).outputSlot(7, 60, 66).outputSlot(8, 80, 66)
|
|
|
|
.outputSlot(9, 100, 66).outputSlot(10, 120, 66).syncEnergyValue()
|
2017-04-08 16:03:46 +02:00
|
|
|
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create();
|
2017-01-08 20:34:46 +01:00
|
|
|
}
|
2017-06-02 21:32:03 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBeUpgraded() {
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-28 00:51:06 +02:00
|
|
|
}
|