- 7
- 1
- 0
Делаю мод и хочу сделать крафт определённого слитка из 1000mb кол-ва материи + слитка уровнем меньше. В ic2 api видел TankGauge но не понял как это использовать. Нужно чтоб был слот для ёмкости, бак визуальный, слоты вход/выход и чтоб можно было как-то рецепты добавлять та и всё..
Код MachineTEs:
package everr.BetterTech.Machines;
import java.util.Set;
import ic2.core.block.TileEntityBlock;
import ic2.core.ref.TeBlock.DefaultDrop;
import ic2.core.ref.TeBlock.HarvestTool;
import ic2.core.util.Util;
import net.minecraft.block.material.Material;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.registry.GameRegistry;
public enum MachineTEs implements ic2.core.block.ITeBlock {
ironinfuser(everr.BetterTech.Machines.MachineIronInfuser.class, 1);
private final Class<? extends TileEntityBlock> teClass;
private final int itemMeta;
private TileEntityBlock dummyTe;
public static final ResourceLocation LOCATION = new ResourceLocation("bettertech", "machine");
private MachineTEs(Class<? extends TileEntityBlock> teClass, int itemMeta) {
this.teClass = teClass;
this.itemMeta = itemMeta;
GameRegistry.registerTileEntity(teClass, "bettertech" + this.getName());
}
public boolean hasItem() {
return true;
}
public String getName() {
return this.name();
}
public int getId() {
return this.itemMeta;
}
public ResourceLocation getIdentifier() {
return LOCATION;
}
public Class<? extends TileEntityBlock> getTeClass() {
return this.teClass;
}
public boolean hasActive() {
return true;
}
public float getHardness() {
return 5.0F;
}
public float getExplosionResistance() {
return 10.0F;
}
public HarvestTool getHarvestTool() {
return HarvestTool.Pickaxe;
}
public DefaultDrop getDefaultDrop() {
return DefaultDrop.Machine;
}
public boolean allowWrenchRotating() {
return false;
}
public Set<EnumFacing> getSupportedFacings() {
return Util.horizontalFacings;
}
public EnumRarity getRarity() {
return EnumRarity.COMMON;
}
public Material getMaterial() {
return Material.IRON;
}
public String[] getRecipeCategories() {
return new String[]{this.getName()};
}
public static void buildDummies() {
ModContainer mc = Loader.instance().activeModContainer();
if(mc != null) {
MachineTEs[] var1 = values();
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
MachineTEs block = var1[var3];
if(block.teClass != null) {
try {
block.dummyTe = (TileEntityBlock)block.teClass.newInstance();
} catch (Exception var6) {
if(Util.inDev()) {
var6.printStackTrace();
}
}
}
}
} else {
throw new IllegalAccessError("Something went wrong (MachineTEs).");
}
}
public TileEntityBlock getDummyTe() {
return this.dummyTe;
}
}
Код MachineIronInfuser:
package everr.BetterTech.Machines;
public class MachineIronInfuser extends TileEntityTestMachine {
public MachineIronInfuser() {
super(1, ic2.api.recipe.Recipes.ironInfuser);
}
public String getSound() {
return "Macerator/MaceratorOp.ogg";
}
}
ironinfuser.xml:
<?xml version="1.0" encoding="UTF-8"?>
<gui width="176" height="166">
<text y="6" align="center">Наполнитель железа</text>
<slot name="input" x="50" y="17"/>
<slot name="output" x="113" y="35"/>
<!--<slotgrid name="output" x="113" y="35" rows="1" style="plain"/>-->
<slot name="discharge" x="50" y="52"/>
<environment name="game">
<button type="recipe" x="77" y="37" width="22" height="15" event="electric_centrifuge"></button>
</environment>
<energygauge x="55" y="37"/>
<gauge name="progress" x="77" y="37" style="progressarrow"/>
<!-- styles:
style="fuel" - Прогресс сгорания топлива (как в генераторе), снизу-вверх
style="bucket" - Прогресс наполнения ведра (как в водяной мельнице), снизу-вверх
style="progresswind" - Прогресс уровня ветра (как в ветряке), снизу-вверх
style="progressarrow" - Прогресс в стиле печки. Стрелка, слева-направо
style="progressarrowmodern" - Новый дизайм стрелки. Стрелка, слева-направо
style="progresscrush" - В стиле дробителя, слева-направо
style="progresstriangle" - В стиле компрессора, слева-направо
style="progressdrop" - В стиле экстрактора, слева-направо
-->
<playerInventory x="7" y="83"/>
</gui>
Код TileEntityTestMachine:
package everr.BetterTech.Machines;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Set;
import ic2.api.recipe.IMachineRecipeManager;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.MachineRecipeResult;
import ic2.api.upgrade.IUpgradableBlock;
import ic2.api.upgrade.IUpgradeItem;
import ic2.api.upgrade.UpgradableProperty;
import ic2.core.ContainerBase;
import ic2.core.IHasGui;
import ic2.core.block.comp.Redstone;
import ic2.core.block.invslot.InvSlotOutput;
import ic2.core.block.invslot.InvSlotProcessable;
import ic2.core.block.invslot.InvSlotProcessableGeneric;
import ic2.core.block.invslot.InvSlotUpgrade;
import ic2.core.block.machine.tileentity.TileEntityElectricMachine;
import ic2.core.gui.TankGauge;
import ic2.core.gui.dynamic.DynamicContainer;
import ic2.core.gui.dynamic.DynamicGui;
import ic2.core.gui.dynamic.GuiParser;
import ic2.core.gui.dynamic.IGuiValueProvider;
import ic2.core.network.GuiSynced;
import ic2.core.util.StackUtil;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityTestMachine extends TileEntityElectricMachine implements IHasGui, IGuiValueProvider, IUpgradableBlock{
protected final int idleEU;
protected final int activeEU;
protected final int maxProgress;
public final InvSlotProcessable<IRecipeInput, Collection<ItemStack>, ItemStack> inputSlot;
public final InvSlotOutput outputSlot;
public final InvSlotUpgrade upgradeSlot;
protected final Redstone redstone;
@GuiSynced public int progress;
public TileEntityTestMachine(int tier, IMachineRecipeManager<IRecipeInput, Collection<ItemStack>, ItemStack> recipeSet) {
this(tier, recipeSet, 1, 25);
}
public TileEntityTestMachine(int tier, IMachineRecipeManager<IRecipeInput, Collection<ItemStack>, ItemStack> recipeSet, int idleEU, int activeEU) {
super(6000, 1);
this.maxProgress = 1000;
this.progress = 0;
this.idleEU = idleEU;
this.activeEU = activeEU;
this.inputSlot = new InvSlotProcessableGeneric(this, "input", 1, recipeSet);
this.outputSlot = new InvSlotOutput(this, "output", 1);
this.upgradeSlot = new InvSlotUpgrade(this, "upgrade", 2);
this.redstone = (Redstone)this.addComponent(new Redstone(this));
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.progress = nbt.getInteger("progress");
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setInteger("progress", this.progress);
return nbt;
}
protected void onUnloaded() {
super.onUnloaded();
}
protected boolean canRun() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public GuiScreen getGui(EntityPlayer p, boolean arg1) {
return DynamicGui.create(this, p, GuiParser.parse(this.teBlock));
}
@Override
public ContainerBase<? extends TileEntityElectricMachine> getGuiContainer(EntityPlayer p) {
return DynamicContainer.create(this, p, GuiParser.parse(this.teBlock));
}
@Override
public void onGuiClosed(EntityPlayer arg0) {}
@Override
public double getGuiValue(String arg0) {
return (double)(1000 * this.progress / this.maxProgress) / 1000.0D;
}
@Override
public double getEnergy() {
return 0;
}
@Override
public boolean useEnergy(double amount) {
return this.energy.useEnergy(amount);
}
@Override
public Set<UpgradableProperty> getUpgradableProperties() {
return EnumSet.of(UpgradableProperty.RedstoneSensitive, UpgradableProperty.ItemConsuming, UpgradableProperty.ItemProducing);
}
protected void updateEntityServer() {
super.updateEntityServer();
boolean needsInvUpdate = false;
boolean canOperate = this.canOperate();
if (this.progress >= this.maxProgress) {
while(true) {
if (this.progress < this.maxProgress || !canOperate) {
needsInvUpdate = true;
break;
}
this.operate();
this.progress -= this.maxProgress;
canOperate = this.canOperate();
}
}
if (this.canRun()) {
if (canOperate && this.energy.useEnergy((double)this.activeEU)) {
this.progress += 10;
} else {
this.progress = 0;
}
} else {
this.progress = 0;
}
Iterator<ItemStack> var4 = this.upgradeSlot.iterator();
while(var4.hasNext()) {
ItemStack stack = (ItemStack)var4.next();
if (!StackUtil.isEmpty(stack) && stack.getItem() instanceof IUpgradeItem) {
needsInvUpdate |= ((IUpgradeItem)stack.getItem()).onTick(stack, this);
}
}
this.setActive(true);
if (needsInvUpdate) {
this.markDirty();
}
}
public boolean canOperate() {
if (this.inputSlot.isEmpty()) {
return false;
}
final MachineRecipeResult<IRecipeInput, Collection<ItemStack>, ItemStack> output = (MachineRecipeResult<IRecipeInput, Collection<ItemStack>, ItemStack>)this.inputSlot.process();
return output != null && this.outputSlot.canAdd((Collection<ItemStack>)output.getOutput());
}
public void operate() {
this.canOperate();
final MachineRecipeResult<IRecipeInput, Collection<ItemStack>, ItemStack> output = (MachineRecipeResult<IRecipeInput, Collection<ItemStack>, ItemStack>)this.inputSlot.process();
this.processUpgrades((Collection<ItemStack>)output.getOutput());
this.outputSlot.add((Collection<ItemStack>)output.getOutput());
this.inputSlot.consume((MachineRecipeResult<IRecipeInput, Collection<ItemStack>, ItemStack>)output);
}
protected void processUpgrades(final Collection<ItemStack> output) {
for (final ItemStack stack : this.upgradeSlot) {
if (stack != null && stack.getItem() instanceof IUpgradeItem) {
((IUpgradeItem)stack.getItem()).onProcessEnd(stack, (IUpgradableBlock)this, (Collection<ItemStack>)output);
}
}
}
}