TechReborn/src/main/java/techreborn/tiles/TileMatterFabricator.java

239 lines
6.6 KiB
Java
Raw Normal View History

/*
* 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-01-08 15:22:59 +01:00
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
2016-10-08 21:46:16 +02:00
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
2015-11-08 13:15:45 +01:00
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
2017-01-08 15:22:59 +01:00
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
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
public class TileMatterFabricator extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IContainerProvider {
2016-03-25 10:47:34 +01:00
public int fabricationRate = 10000;
2016-03-25 10:47:34 +01:00
public int tickTime;
public Inventory inventory = new Inventory(7, "TileMatterFabricator", 64, this);
private int amplifier = 0;
2016-10-08 21:46:16 +02:00
public TileMatterFabricator() {
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) {
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) {
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;
}
2016-10-08 21:46:16 +02:00
// // ISidedInventory
// @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);
// }
//
// @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() {
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-03-13 12:04:10 +01:00
if (!stack.isEmpty()) {
final int amp = this.getValue(stack);
if(amp != 0 && this.canUseEnergy(85)){
this.useEnergy(85);
this.amplifier += amp;
this.inventory.decrStackSize(i, 1);
2016-03-25 10:47:34 +01:00
}
}
}
if(amplifier >= fabricationRate){
if(spaceForOutput()){
this.addOutputProducts();
amplifier -= fabricationRate;
2016-03-25 10:47:34 +01:00
}
}
}
}
2016-10-08 21:46:16 +02:00
private boolean spaceForOutput() {
2017-01-08 15:22:59 +01:00
return this.inventory.getStackInSlot(6) == ItemStack.EMPTY
|| ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)
&& this.inventory.getStackInSlot(6).getCount() < 64;
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
private void addOutputProducts() {
2016-03-25 10:47:34 +01:00
2017-01-08 15:22:59 +01:00
if (this.inventory.getStackInSlot(6) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(6, new ItemStack(ModItems.UU_MATTER));
} else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)) {
this.inventory.getStackInSlot(6).setCount(Math.min(64, 1 + this.inventory.getStackInSlot(6).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;
}
}
2016-03-25 10:47:34 +01:00
}
2017-01-08 15:22:59 +01:00
public int getValue(final ItemStack itemStack) {
if (itemStack.getItem() == ModItems.PARTS && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) {
return 200;
} else if (itemStack.getItem() == ModItems.SCRAP_BOX) {
return 2000;
}
if(IC2Duplicates.SCRAP.hasIC2Stack()){
if(ItemUtils.isInputEqual(itemStack, IC2Duplicates.SCRAP.getIc2Stack(), true, true, true)){
return 200;
}
2016-03-27 19:56:27 +02:00
}
2016-03-25 10:47:34 +01:00
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxPower() {
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) {
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) {
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxOutput() {
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxInput() {
return 4096;
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public EnumPowerTier getTier() {
2016-03-25 10:47:34 +01:00
return EnumPowerTier.EXTREME;
}
@Override
public Inventory getInventory() {
2017-01-08 15:22:59 +01:00
return this.inventory;
}
public int getProgress() {
return this.amplifier;
2017-01-08 15:22:59 +01:00
}
public void setProgress(final int progress) {
this.amplifier = progress;
2017-01-08 15:22:59 +01:00
}
public int getProgressScaled(final int scale) {
if (this.amplifier != 0) {
return Math.min(this.amplifier * scale / fabricationRate, 100);
2017-01-08 15:22:59 +01:00
}
return 0;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("matterfabricator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 33, 17).slot(1, 33, 35).slot(2, 33, 53).slot(3, 51, 17)
.slot(4, 51, 35).slot(5, 51, 53).outputSlot(6, 116, 35).syncEnergyValue()
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create();
}
2015-04-28 00:51:06 +02:00
}