Framework for ARC
Initial framework for the ARC block, including GUI, Container, Tile Entity, and Block.
This commit is contained in:
parent
2a8143844a
commit
ec1b0644cb
32 changed files with 847 additions and 70 deletions
|
@ -0,0 +1,129 @@
|
|||
package wayoftime.bloodmagic.tile;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import wayoftime.bloodmagic.tile.contailer.ContainerAlchemicalReactionChamber;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
||||
public class TileAlchemicalReactionChamber extends TileInventory implements ITickableTileEntity, INamedContainerProvider
|
||||
{
|
||||
@ObjectHolder("bloodmagic:alchemicalreactionchamber")
|
||||
public static TileEntityType<TileAlchemicalReactionChamber> TYPE;
|
||||
|
||||
public static final int ARC_TOOL_SLOT = 0;
|
||||
public static final int OUTPUT_SLOT = 1;
|
||||
public static final int NUM_OUTPUTS = 5;
|
||||
public static final int INPUT_SLOT = 6;
|
||||
public static final int INPUT_BUCKET_SLOT = 7;
|
||||
public static final int OUTPUT_BUCKET_SLOT = 8;
|
||||
|
||||
public FluidTank inputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 2);
|
||||
public FluidTank outputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 2);
|
||||
|
||||
// Input slots are from 0 to 3.
|
||||
|
||||
public int burnTime = 0;
|
||||
|
||||
public TileAlchemicalReactionChamber(TileEntityType<?> type)
|
||||
{
|
||||
super(type, 9, "alchemicalreactionchamber");
|
||||
}
|
||||
|
||||
public TileAlchemicalReactionChamber()
|
||||
{
|
||||
this(TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(CompoundNBT tag)
|
||||
{
|
||||
super.deserialize(tag);
|
||||
|
||||
burnTime = tag.getInt(Constants.NBT.SOUL_FORGE_BURN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serialize(CompoundNBT tag)
|
||||
{
|
||||
super.serialize(tag);
|
||||
|
||||
tag.putInt(Constants.NBT.SOUL_FORGE_BURN, burnTime);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// private boolean canCraft(RecipeTartaricForge recipe)
|
||||
// {
|
||||
// if (recipe == null)
|
||||
// return false;
|
||||
//
|
||||
// ItemStack currentOutputStack = getStackInSlot(outputSlot);
|
||||
// if (recipe.getOutput().isEmpty())
|
||||
// return false;
|
||||
// if (currentOutputStack.isEmpty())
|
||||
// return true;
|
||||
// if (!currentOutputStack.isItemEqual(recipe.getOutput()))
|
||||
// return false;
|
||||
// int result = currentOutputStack.getCount() + recipe.getOutput().getCount();
|
||||
// return result <= getInventoryStackLimit() && result <= currentOutputStack.getMaxStackSize();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void craftItem(RecipeTartaricForge recipe)
|
||||
// {
|
||||
// if (this.canCraft(recipe))
|
||||
// {
|
||||
// ItemStack currentOutputStack = getStackInSlot(outputSlot);
|
||||
//
|
||||
// List<ItemStack> inputList = new ArrayList<>();
|
||||
// for (int i = 0; i < 4; i++) if (!getStackInSlot(i).isEmpty())
|
||||
// inputList.add(getStackInSlot(i).copy());
|
||||
//
|
||||
// BloodMagicCraftedEvent.SoulForge event = new BloodMagicCraftedEvent.SoulForge(recipe.getOutput().copy(), inputList.toArray(new ItemStack[0]));
|
||||
// MinecraftForge.EVENT_BUS.post(event);
|
||||
//
|
||||
// if (currentOutputStack.isEmpty())
|
||||
// {
|
||||
// setInventorySlotContents(outputSlot, event.getOutput());
|
||||
// } else if (ItemHandlerHelper.canItemStacksStack(currentOutputStack, event.getOutput()))
|
||||
// {
|
||||
// currentOutputStack.grow(event.getOutput().getCount());
|
||||
// }
|
||||
//
|
||||
// consumeInventory();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_)
|
||||
{
|
||||
assert world != null;
|
||||
return new ContainerAlchemicalReactionChamber(this, p_createMenu_1_, p_createMenu_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return new StringTextComponent("Alchemical Reaction Chamber");
|
||||
}
|
||||
|
||||
public double getProgressForGui()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
package wayoftime.bloodmagic.tile.contailer;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
|
||||
import wayoftime.bloodmagic.common.item.IARCTool;
|
||||
import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber;
|
||||
|
||||
public class ContainerAlchemicalReactionChamber extends Container
|
||||
{
|
||||
public final TileAlchemicalReactionChamber tileARC;
|
||||
|
||||
// public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileARC)
|
||||
// {
|
||||
// this.tileARC = tileARC;
|
||||
//
|
||||
// }
|
||||
|
||||
public ContainerAlchemicalReactionChamber(int windowId, PlayerInventory playerInventory, PacketBuffer extraData)
|
||||
{
|
||||
this((TileAlchemicalReactionChamber) playerInventory.player.world.getTileEntity(extraData.readBlockPos()), windowId, playerInventory);
|
||||
}
|
||||
|
||||
public ContainerAlchemicalReactionChamber(@Nullable TileAlchemicalReactionChamber tile, int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
super(BloodMagicBlocks.ARC_CONTAINER.get(), windowId);
|
||||
this.tileARC = tile;
|
||||
this.setup(playerInventory, tile);
|
||||
}
|
||||
|
||||
public void setup(PlayerInventory inventory, IInventory tileARC)
|
||||
{
|
||||
this.addSlot(new SlotARCTool(tileARC, TileAlchemicalReactionChamber.ARC_TOOL_SLOT, 35, 51));
|
||||
for (int i = 0; i < TileAlchemicalReactionChamber.NUM_OUTPUTS; i++)
|
||||
{
|
||||
this.addSlot(new SlotOutput(tileARC, TileAlchemicalReactionChamber.OUTPUT_SLOT + i, 116, 15 + i * 18));
|
||||
}
|
||||
this.addSlot(new Slot(tileARC, TileAlchemicalReactionChamber.INPUT_SLOT, 71, 15));
|
||||
this.addSlot(new SlotBucket(tileARC, TileAlchemicalReactionChamber.INPUT_BUCKET_SLOT, 8, 15, true));
|
||||
this.addSlot(new SlotBucket(tileARC, TileAlchemicalReactionChamber.OUTPUT_BUCKET_SLOT, 152, 87, false));
|
||||
|
||||
// this.addSlot(new SlotSoul(tileARC, TileSoulForge.soulSlot, 152, 51));
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 9; j++)
|
||||
{
|
||||
addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
addSlot(new Slot(inventory, i, 8 + i * 18, 181));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot = this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if ((index >= 1 && index < 1 + 5) || (index == 7 || index == 8))// Attempting to transfer from output slots
|
||||
// or bucket slots
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
} else if (index > 9) // Attempting to transfer from main inventory
|
||||
{
|
||||
if (itemstack1.getItem() instanceof IARCTool) // Try the tool slot first
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isBucket(itemstack1, true)) // If it's a full bucket, transfer to tank filler slot.
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 7, 8, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isBucket(itemstack1, false)) // If it's an empty bucket, transfer to tank emptier slot.
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 8, 9, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 6, 7, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 9, 45, false)) // Attempting to transfer from input slots
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemstack1.getCount() == 0)
|
||||
{
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.getCount() == itemstack.getCount())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onTake(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn)
|
||||
{
|
||||
return this.tileARC.isUsableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
private class SlotARCTool extends Slot
|
||||
{
|
||||
public SlotARCTool(IInventory inventory, int slotIndex, int x, int y)
|
||||
{
|
||||
super(inventory, slotIndex, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItem() instanceof IARCTool;
|
||||
}
|
||||
}
|
||||
|
||||
private class SlotBucket extends Slot
|
||||
{
|
||||
private final boolean needsFullBucket;
|
||||
|
||||
public SlotBucket(IInventory inventory, int slotIndex, int x, int y, boolean needsFullBucket)
|
||||
{
|
||||
super(inventory, slotIndex, x, y);
|
||||
this.needsFullBucket = needsFullBucket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
Optional<FluidStack> fluidStackOptional = FluidUtil.getFluidContained(itemStack);
|
||||
|
||||
return fluidStackOptional.isPresent() && ((needsFullBucket && !fluidStackOptional.get().isEmpty())
|
||||
|| (!needsFullBucket && fluidStackOptional.get().isEmpty()));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBucket(ItemStack stack, boolean requiredFull)
|
||||
{
|
||||
Optional<FluidStack> fluidStackOptional = FluidUtil.getFluidContained(stack);
|
||||
|
||||
return fluidStackOptional.isPresent() && ((requiredFull && !fluidStackOptional.get().isEmpty())
|
||||
|| (!requiredFull && fluidStackOptional.get().isEmpty()));
|
||||
}
|
||||
|
||||
private class SlotOutput extends Slot
|
||||
{
|
||||
public SlotOutput(IInventory inventory, int slotIndex, int x, int y)
|
||||
{
|
||||
super(inventory, slotIndex, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue