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

195 lines
6.4 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.
*/
package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing;
2015-11-08 13:15:45 +01:00
import reborncore.api.IListInfoProvider;
import reborncore.api.power.IEnergyItemInfo;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
2017-08-30 22:57:14 +02:00
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PoweredItem;
import reborncore.common.powerSystem.TilePowerAcceptor;
2016-04-11 18:23:57 +02:00
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
2015-04-14 20:23:16 +02:00
import techreborn.init.ModBlocks;
2016-12-13 00:57:04 +01:00
import techreborn.items.DynamicCell;
import techreborn.lib.ModInfo;
import java.util.List;
@RebornRegistry(modID = ModInfo.MOD_ID)
2017-06-14 01:49:52 +02:00
public class TileIndustrialCentrifuge extends TilePowerAcceptor
2017-08-30 22:57:14 +02:00
implements IToolDrop, IInventoryProvider, IListInfoProvider, IRecipeCrafterProvider, IContainerProvider {
2016-03-25 10:47:34 +01:00
@ConfigRegistry(config = "machines", category = "centrifuge", key = "CentrifugeMaxInput", comment = "Centrifuge Max Input (Value in EU)")
public static int maxInput = 32;
@ConfigRegistry(config = "machines", category = "centrifuge", key = "CentrifugeMaxEnergy", comment = "Centrifuge Max Energy (Value in EU)")
public static int maxEnergy = 10000;
// @ConfigRegistry(config = "machines", category = "centrifuge", key = "CentrifugeWrenchDropRate", comment = "Centrifuge Wrench Drop Rate")
public static float wrenchDropRate = 1.0F;
2016-03-25 10:47:34 +01:00
public int tickTime;
2017-06-14 01:49:52 +02:00
public Inventory inventory = new Inventory(11, "TileIndustrialCentrifuge", 64, this);
2016-03-25 10:47:34 +01:00
public RecipeCrafter crafter;
2017-06-14 01:49:52 +02:00
public TileIndustrialCentrifuge() {
super();
2016-03-25 10:47:34 +01:00
// Input slots
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[4];
2016-03-25 10:47:34 +01:00
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
2016-12-13 00:57:04 +01:00
outputs[3] = 5;
this.crafter = new RecipeCrafter(Reference.centrifugeRecipe, this, 2, 4, this.inventory, inputs, outputs);
2016-03-25 10:47:34 +01:00
}
2016-12-13 00:57:04 +01:00
@Override
2016-10-08 21:46:16 +02:00
public void updateEntity() {
super.updateEntity();
this.crafter.updateEntity();
this.charge(6);
if (this.inventory.getStackInSlot(6) != ItemStack.EMPTY) {
final ItemStack stack = this.inventory.getStackInSlot(6);
2016-10-08 21:46:16 +02:00
if (stack.getItem() instanceof IEnergyItemInfo) {
final IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
2016-10-08 21:46:16 +02:00
if (item.canProvideEnergy(stack)) {
if (this.getEnergy() != this.getMaxPower()) {
this.addEnergy(item.getMaxTransfer(stack));
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack);
}
}
}
}
2016-12-13 00:57:04 +01:00
}
2016-03-25 10:47:34 +01:00
@Override
2017-08-30 22:57:14 +02:00
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_CENTRIFUGE, 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;
}
@Override
public void readFromNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
this.crafter.readFromNBT(tagCompound);
2016-03-25 10:47:34 +01:00
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
2016-05-18 17:53:54 +02:00
return tagCompound;
2016-03-25 10:47:34 +01:00
}
// ISidedInventory
2016-12-13 00:57:04 +01:00
@Override
public int[] getSlotsForFace(final EnumFacing side) {
2016-12-13 00:57:04 +01:00
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
2016-12-13 00:57:04 +01:00
return itemStackIn.isItemEqual(DynamicCell.getEmptyCell(1).copy()) ? index == 1 : index == 0;
}
@Override
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex >= 2 && slotIndex <= 5;
2016-12-13 00:57:04 +01:00
}
2016-03-25 10:47:34 +01:00
@Override
public void addInfo(final List<String> info, final boolean isRealTile) {
2016-03-25 10:47:34 +01:00
super.addInfo(info, isRealTile);
info.add("Round and round it goes");
}
2016-10-08 21:46:16 +02:00
public int getProgressScaled(final int scale) {
if (this.crafter.currentTickTime != 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
2016-03-25 10:47:34 +01:00
}
return 0;
}
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxPower() {
return maxEnergy;
}
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxOutput() {
return 0;
}
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxInput() {
return maxInput;
2016-03-25 10:47:34 +01:00
}
@Override
public Inventory getInventory() {
return this.inventory;
2016-03-25 10:47:34 +01:00
}
@Override
public RecipeCrafter getRecipeCrafter() {
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
2017-01-08 21:29:14 +01:00
return new ContainerBuilder("centrifuge").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 40, 34).slot(1, 40, 54).outputSlot(2, 82, 44).outputSlot(3, 101, 25)
.outputSlot(4, 120, 44).outputSlot(5, 101, 63).energySlot(6, 8, 72).syncEnergyValue()
.syncCrafterValue().addInventory().create(this);
}
2016-04-12 09:33:38 +02:00
}