Made Storage upgrades functional
This commit is contained in:
parent
ad4c4befe7
commit
c30c3084ae
|
@ -172,7 +172,6 @@ public class CompactingDrawerBlock extends RotatableBlock<CompactingDrawerTile>
|
|||
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
TileUtil.getTileEntity(worldIn, pos, DrawerTile.class).ifPresent(tile -> {
|
||||
if (tile.getControllerPos() != null){
|
||||
System.out.println(TileUtil.getTileEntity(worldIn, tile.getControllerPos()).get());
|
||||
TileUtil.getTileEntity(worldIn, tile.getControllerPos(), DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
|
||||
drawerControllerTile.addConnectedDrawers(LinkingToolItem.ActionMode.REMOVE, pos);
|
||||
});
|
||||
|
|
|
@ -222,7 +222,6 @@ public class DrawerBlock extends RotatableBlock<DrawerTile> {
|
|||
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
TileUtil.getTileEntity(worldIn, pos, DrawerTile.class).ifPresent(tile -> {
|
||||
if (tile.getControllerPos() != null){
|
||||
System.out.println(TileUtil.getTileEntity(worldIn, tile.getControllerPos()).get());
|
||||
TileUtil.getTileEntity(worldIn, tile.getControllerPos(), DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
|
||||
drawerControllerTile.addConnectedDrawers(LinkingToolItem.ActionMode.REMOVE, pos);
|
||||
});
|
||||
|
|
|
@ -44,6 +44,11 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
|
|||
public void onChange() {
|
||||
CompactingDrawerTile.this.markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiplier() {
|
||||
return getStorageMultiplier();
|
||||
}
|
||||
};
|
||||
lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
//TODO Check for the recipe on load
|
||||
|
@ -67,6 +72,11 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStorageSlotAmount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getStorage() {
|
||||
return handler;
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
package com.buuz135.functionalstorage.block.tile;
|
||||
|
||||
import com.buuz135.functionalstorage.item.LinkingToolItem;
|
||||
import com.buuz135.functionalstorage.item.StorageUpgradeItem;
|
||||
import com.buuz135.functionalstorage.item.UpgradeItem;
|
||||
import com.hrznstudio.titanium.annotation.Save;
|
||||
import com.hrznstudio.titanium.block.BasicTileBlock;
|
||||
import com.hrznstudio.titanium.block.tile.ActiveTile;
|
||||
import com.hrznstudio.titanium.client.screen.addon.TextScreenAddon;
|
||||
import com.hrznstudio.titanium.component.inventory.InventoryComponent;
|
||||
import com.hrznstudio.titanium.util.RayTraceUtils;
|
||||
import com.hrznstudio.titanium.util.TileUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -29,9 +35,27 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
|
||||
@Save
|
||||
private BlockPos controllerPos;
|
||||
@Save
|
||||
private InventoryComponent<ControllableDrawerTile<T>> storageUpgrades;
|
||||
@Save
|
||||
private InventoryComponent<ControllableDrawerTile<T>> utilityUpgrades;
|
||||
|
||||
public ControllableDrawerTile(BasicTileBlock<T> base, BlockPos pos, BlockState state) {
|
||||
super(base, pos, state);
|
||||
this.addInventory((InventoryComponent<T>) (this.storageUpgrades = new InventoryComponent<ControllableDrawerTile<T>>("storage_upgrades", 10, 70, getStorageSlotAmount())
|
||||
.setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.STORAGE))
|
||||
);
|
||||
this.addInventory((InventoryComponent<T>) (this.utilityUpgrades = new InventoryComponent<ControllableDrawerTile<T>>("utility_upgrades", 114, 70, 3)
|
||||
.setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.UTILITY))
|
||||
);
|
||||
addGuiAddonFactory(() -> new TextScreenAddon("Storage", 10, 59, false, ChatFormatting.DARK_GRAY.getColor()));
|
||||
addGuiAddonFactory(() -> new TextScreenAddon("Utility", 114, 59, false, ChatFormatting.DARK_GRAY.getColor()));
|
||||
addGuiAddonFactory(() -> new TextScreenAddon("key.categories.inventory", 8, 92, false, ChatFormatting.DARK_GRAY.getColor()){
|
||||
@Override
|
||||
public String getText() {
|
||||
return new TranslatableComponent("key.categories.inventory").getString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public BlockPos getControllerPos() {
|
||||
|
@ -47,6 +71,17 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
this.controllerPos = controllerPos;
|
||||
}
|
||||
|
||||
public int getStorageMultiplier(){
|
||||
int mult = 1;
|
||||
for (int i = 0; i < storageUpgrades.getSlots(); i++) {
|
||||
if (storageUpgrades.getStackInSlot(i).getItem() instanceof StorageUpgradeItem){
|
||||
if (mult == 1) mult = ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
|
||||
else mult *= ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
|
||||
}
|
||||
}
|
||||
return mult;
|
||||
}
|
||||
|
||||
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
|
||||
if (super.onActivated(playerIn, hand, facing, hitX, hitY, hitZ) == InteractionResult.SUCCESS) {
|
||||
return InteractionResult.SUCCESS;
|
||||
|
@ -70,6 +105,8 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
public abstract int getStorageSlotAmount();
|
||||
|
||||
public void onClicked(Player playerIn, int slot) {
|
||||
if (isServer() && slot != -1){
|
||||
HitResult rayTraceResult = RayTraceUtils.rayTraceSimple(this.level, playerIn, 16, 0);
|
||||
|
|
|
@ -45,14 +45,17 @@ public class DrawerControllerTile extends ControllableDrawerTile<DrawerControlle
|
|||
this.lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStorageSlotAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverTick(Level level, BlockPos pos, BlockState state, DrawerControllerTile blockEntity) {
|
||||
super.serverTick(level, pos, state, blockEntity);
|
||||
if (this.connectedDrawers.getConnectedDrawers().size() != this.connectedDrawers.getHandlers().size()){
|
||||
this.connectedDrawers.setLevel(getLevel());
|
||||
this.connectedDrawers.rebuild();
|
||||
//this.lazyStorage.invalidate();
|
||||
//this.lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
markForUpdate();
|
||||
updateNeigh();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@ public class DrawerTile extends ControllableDrawerTile<DrawerTile> {
|
|||
public void onChange() {
|
||||
DrawerTile.this.markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiplier() {
|
||||
return getStorageMultiplier();
|
||||
}
|
||||
};
|
||||
lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
}
|
||||
|
@ -68,6 +73,11 @@ public class DrawerTile extends ControllableDrawerTile<DrawerTile> {
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStorageSlotAmount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getStorage() {
|
||||
return handler;
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount());
|
||||
if (!simulate){
|
||||
bigStack.setStack(stack);
|
||||
bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, type.getSlotAmount()));
|
||||
bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, getSlotLimit(slot)));
|
||||
onChange();
|
||||
}
|
||||
if (inserted == stack.getCount() || voidItems) return ItemStack.EMPTY;
|
||||
|
@ -92,7 +92,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return Math.min(Integer.MAX_VALUE, type.getSlotAmount());
|
||||
return Math.min(Integer.MAX_VALUE, type.getSlotAmount() * getMultiplier());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,6 +131,8 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
|
||||
public abstract void onChange();
|
||||
|
||||
public abstract int getMultiplier();
|
||||
|
||||
public class BigStack{
|
||||
|
||||
private ItemStack stack;
|
||||
|
|
|
@ -18,7 +18,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
public static String STACK = "Stack";
|
||||
public static String AMOUNT = "Amount";
|
||||
|
||||
private final int TOTAL_AMOUNT = 8192 * 9 * 9;
|
||||
private final int TOTAL_AMOUNT = 512 * 9 * 9;
|
||||
|
||||
private int amount;
|
||||
private boolean voidItems;
|
||||
|
@ -51,10 +51,10 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (isItemValid(slot, stack)) {
|
||||
CompactingUtil.Result result = this.resultList.get(slot);
|
||||
int inserted = Math.min(TOTAL_AMOUNT - amount, stack.getCount() * result.getNeeded());
|
||||
int inserted = Math.min(getSlotLimit(slot) * result.getNeeded() - amount, stack.getCount() * result.getNeeded());
|
||||
inserted = (int) (Math.floor(inserted / result.getNeeded()) * result.getNeeded());
|
||||
if (!simulate){
|
||||
this.amount = Math.min(this.amount + inserted, TOTAL_AMOUNT);
|
||||
this.amount = Math.min(this.amount + inserted, TOTAL_AMOUNT * getMultiplier());
|
||||
onChange();
|
||||
}
|
||||
if (inserted == stack.getCount() * result.getNeeded() || voidItems) return ItemStack.EMPTY;
|
||||
|
@ -115,7 +115,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return (int) Math.floor(TOTAL_AMOUNT / this.resultList.get(slot).getNeeded());
|
||||
return (int) Math.min(Integer.MAX_VALUE, Math.floor((TOTAL_AMOUNT * getMultiplier()) / this.resultList.get(slot).getNeeded()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,6 +156,8 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
public abstract void onChange();
|
||||
|
||||
public abstract int getMultiplier();
|
||||
|
||||
public List<CompactingUtil.Result> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ public class UpgradeItem extends BasicItem {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static enum Type{
|
||||
STORAGE,
|
||||
UTILITY
|
||||
|
|
Loading…
Reference in New Issue
Block a user