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

128 lines
3.6 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
2018-02-11 15:08:08 +01:00
* Copyright (c) 2018 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.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import reborncore.api.IToolDrop;
2016-04-11 18:23:57 +02:00
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.powerSystem.TilePowerAcceptor;
2016-04-11 18:23:57 +02:00
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
/**
* @author drcrazy
*
*/
public abstract class TileGenericMachine extends TilePowerAcceptor
implements IToolDrop, IInventoryProvider, IRecipeCrafterProvider{
public String name;
public int maxInput;
public int maxEnergy;
public Block toolDrop;
public int energySlot;
public Inventory inventory;
2016-03-25 10:47:34 +01:00
public RecipeCrafter crafter;
2018-04-02 15:58:03 +02:00
/**
* @param name String Name for a tile. Do we need it at all?
* @param maxInput int Maximum energy input, value in EU
* @param maxEnergy int Maximum energy buffer, value in EU
* @param toolDrop Block Block to drop with wrench
* @param energySlot int Energy slot to use to charge machine from battery
*/
public TileGenericMachine(String name, int maxInput, int maxEnergy, Block toolDrop, int energySlot) {
this.name = "Tile" + name;
this.maxInput = maxInput;
this.maxEnergy = maxEnergy;
this.toolDrop = toolDrop;
this.energySlot = energySlot;
2018-04-02 23:31:26 +02:00
checkTeir();
2016-03-25 10:47:34 +01:00
}
2018-03-30 16:32:44 +02:00
public int getProgressScaled(final int scale) {
if (this.crafter != null && this.crafter.currentTickTime != 0) {
2018-03-30 16:32:44 +02:00
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
}
return 0;
}
2018-03-30 16:32:44 +02:00
// TilePowerAcceptor
2016-03-25 10:47:34 +01:00
@Override
public void update() {
super.update();
2017-01-08 23:49:09 +01:00
if (!this.world.isRemote) {
this.charge(energySlot);
2017-01-08 23:49:09 +01:00
}
2016-03-25 10:47:34 +01:00
}
2016-03-25 10:47:34 +01:00
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxPower() {
2018-03-30 16:32:44 +02:00
return maxEnergy;
2016-03-25 10:47:34 +01:00
}
@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() {
2018-03-30 16:32:44 +02:00
return maxInput;
}
2018-03-30 16:32:44 +02:00
// IToolDrop
2016-03-25 10:47:34 +01:00
@Override
public ItemStack getToolDrop(EntityPlayer p0) {
return new ItemStack(toolDrop, 1);
2016-03-25 10:47:34 +01:00
}
2018-03-30 16:32:44 +02:00
// IInventoryProvider
2016-03-25 10:47:34 +01:00
@Override
2018-03-30 16:32:44 +02:00
public Inventory getInventory() {
return inventory;
2016-03-25 10:47:34 +01:00
}
2018-03-30 16:32:44 +02:00
// IRecipeCrafterProvider
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
2018-03-30 16:32:44 +02:00
}
}