Made Void upgrade functional and added direction swapping for the other utility upgrades
This commit is contained in:
parent
c30c3084ae
commit
ddff5a8f3a
|
@ -49,13 +49,18 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
|
|||
public int getMultiplier() {
|
||||
return getStorageMultiplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoid() {
|
||||
return CompactingDrawerTile.this.isVoid();
|
||||
}
|
||||
};
|
||||
lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
//TODO Check for the recipe on load
|
||||
}
|
||||
|
||||
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
|
||||
if (!handler.isSetup()){
|
||||
if (!handler.isSetup() && slot != -1){
|
||||
ItemStack stack = playerIn.getItemInHand(hand).copy();
|
||||
stack.setCount(1);
|
||||
CompactingUtil compactingUtil = new CompactingUtil(this.level);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.buuz135.functionalstorage.block.tile;
|
||||
|
||||
import com.buuz135.functionalstorage.FunctionalStorage;
|
||||
import com.buuz135.functionalstorage.item.LinkingToolItem;
|
||||
import com.buuz135.functionalstorage.item.StorageUpgradeItem;
|
||||
import com.buuz135.functionalstorage.item.UpgradeItem;
|
||||
|
@ -33,6 +34,10 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
|
||||
private static HashMap<UUID, Long> INTERACTION_LOGGER = new HashMap<>();
|
||||
|
||||
//TODO Lock the slots for the upgrades
|
||||
//TODO Add support for the iron upgrade
|
||||
|
||||
|
||||
@Save
|
||||
private BlockPos controllerPos;
|
||||
@Save
|
||||
|
@ -43,10 +48,13 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
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))
|
||||
.setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.STORAGE)
|
||||
.setSlotLimit(1)
|
||||
)
|
||||
);
|
||||
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))
|
||||
.setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.UTILITY)
|
||||
.setSlotLimit(1))
|
||||
);
|
||||
addGuiAddonFactory(() -> new TextScreenAddon("Storage", 10, 59, false, ChatFormatting.DARK_GRAY.getColor()));
|
||||
addGuiAddonFactory(() -> new TextScreenAddon("Utility", 114, 59, false, ChatFormatting.DARK_GRAY.getColor()));
|
||||
|
@ -82,6 +90,15 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
|
|||
return mult;
|
||||
}
|
||||
|
||||
public boolean isVoid(){
|
||||
for (int i = 0; i < this.utilityUpgrades.getSlots(); i++) {
|
||||
if (this.utilityUpgrades.getStackInSlot(i).getItem().equals(FunctionalStorage.VOID_UPGRADE.get())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -50,6 +50,11 @@ public class DrawerTile extends ControllableDrawerTile<DrawerTile> {
|
|||
public int getMultiplier() {
|
||||
return getStorageMultiplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoid() {
|
||||
return DrawerTile.this.isVoid();
|
||||
}
|
||||
};
|
||||
lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
|
||||
private final FunctionalStorage.DrawerType type;
|
||||
private List<BigStack> storedStacks;
|
||||
private boolean voidItems;
|
||||
|
||||
public BigInventoryHandler(FunctionalStorage.DrawerType type){
|
||||
this.type = type;
|
||||
|
@ -28,7 +27,6 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
for (int i = 0; i < type.getSlots(); i++) {
|
||||
this.storedStacks.add(i, new BigStack(ItemStack.EMPTY, 0));
|
||||
}
|
||||
this.voidItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +54,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, getSlotLimit(slot)));
|
||||
onChange();
|
||||
}
|
||||
if (inserted == stack.getCount() || voidItems) return ItemStack.EMPTY;
|
||||
if (inserted == stack.getCount() || isVoid()) return ItemStack.EMPTY;
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - inserted);
|
||||
}
|
||||
return stack;
|
||||
|
@ -108,7 +106,6 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
compoundTag.putBoolean(VOID, voidItems);
|
||||
CompoundTag items = new CompoundTag();
|
||||
for (int i = 0; i < this.storedStacks.size(); i++) {
|
||||
CompoundTag bigStack = new CompoundTag();
|
||||
|
@ -122,7 +119,6 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.voidItems = nbt.getBoolean(VOID);
|
||||
for (String allKey : nbt.getCompound(BIG_ITEMS).getAllKeys()) {
|
||||
this.storedStacks.get(Integer.parseInt(allKey)).setStack(ItemStack.of(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getCompound(STACK)));
|
||||
this.storedStacks.get(Integer.parseInt(allKey)).setAmount(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getInt(AMOUNT));
|
||||
|
@ -133,6 +129,8 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
|
|||
|
||||
public abstract int getMultiplier();
|
||||
|
||||
public abstract boolean isVoid();
|
||||
|
||||
public class BigStack{
|
||||
|
||||
private ItemStack stack;
|
||||
|
|
|
@ -21,7 +21,6 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
private final int TOTAL_AMOUNT = 512 * 9 * 9;
|
||||
|
||||
private int amount;
|
||||
private boolean voidItems;
|
||||
private List<CompactingUtil.Result> resultList;
|
||||
|
||||
public CompactingInventoryHandler(){
|
||||
|
@ -29,7 +28,6 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
for (int i = 0; i < 3; i++) {
|
||||
this.resultList.add(i, new CompactingUtil.Result(ItemStack.EMPTY, 1));
|
||||
}
|
||||
this.voidItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +55,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
this.amount = Math.min(this.amount + inserted, TOTAL_AMOUNT * getMultiplier());
|
||||
onChange();
|
||||
}
|
||||
if (inserted == stack.getCount() * result.getNeeded() || voidItems) return ItemStack.EMPTY;
|
||||
if (inserted == stack.getCount() * result.getNeeded() || isVoid()) return ItemStack.EMPTY;
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - inserted / result.getNeeded());
|
||||
|
||||
}
|
||||
|
@ -131,7 +129,6 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
compoundTag.putBoolean(VOID, voidItems);
|
||||
compoundTag.putInt(AMOUNT, this.amount);
|
||||
CompoundTag items = new CompoundTag();
|
||||
for (int i = 0; i < this.resultList.size(); i++) {
|
||||
|
@ -146,7 +143,6 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.voidItems = nbt.getBoolean(VOID);
|
||||
this.amount = nbt.getInt(AMOUNT);
|
||||
for (String allKey : nbt.getCompound(BIG_ITEMS).getAllKeys()) {
|
||||
this.resultList.get(Integer.parseInt(allKey)).setResult(ItemStack.of(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getCompound(STACK)));
|
||||
|
@ -158,6 +154,8 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
public abstract int getMultiplier();
|
||||
|
||||
public abstract boolean isVoid();
|
||||
|
||||
public List<CompactingUtil.Result> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,26 @@ package com.buuz135.functionalstorage.item;
|
|||
|
||||
import com.buuz135.functionalstorage.FunctionalStorage;
|
||||
import com.hrznstudio.titanium.item.BasicItem;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.entity.SlotAccess;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ClickAction;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class UpgradeItem extends BasicItem {
|
||||
|
||||
|
@ -12,10 +32,68 @@ public class UpgradeItem extends BasicItem {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedBy(ItemStack p_41447_, Level p_41448_, Player p_41449_) {
|
||||
super.onCraftedBy(p_41447_, p_41448_, p_41449_);
|
||||
initNbt(p_41447_);
|
||||
}
|
||||
|
||||
private ItemStack initNbt(ItemStack stack){
|
||||
Item item = stack.getItem();
|
||||
if (item.equals(FunctionalStorage.PULLING_UPGRADE.get()) || item.equals(FunctionalStorage.PUSHING_UPGRADE.get()) || item.equals(FunctionalStorage.COLLECTOR_UPGRADE.get())){
|
||||
stack.getOrCreateTag().putString("Direction", Direction.values()[0].name());
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> items) {
|
||||
if (allowdedIn(group)) {
|
||||
items.add(initNbt(new ItemStack(this)));
|
||||
}
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean overrideStackedOnOther(ItemStack p_150888_, Slot p_150889_, ClickAction p_150890_, Player p_150891_) {
|
||||
return super.overrideStackedOnOther(p_150888_, p_150889_, p_150890_, p_150891_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean overrideOtherStackedOnMe(ItemStack first, ItemStack second, Slot p_150894_, ClickAction clickAction, Player p_150896_, SlotAccess p_150897_) {
|
||||
if (clickAction == ClickAction.SECONDARY && first.getCount() == 1 && first.hasTag()){
|
||||
Item item = first.getItem();
|
||||
if (item.equals(FunctionalStorage.PULLING_UPGRADE.get()) || item.equals(FunctionalStorage.PUSHING_UPGRADE.get()) || item.equals(FunctionalStorage.COLLECTOR_UPGRADE.get())){
|
||||
Direction direction = Direction.byName(first.getOrCreateTag().getString("Direction"));
|
||||
Direction next = Direction.values()[(Arrays.asList(Direction.values()).indexOf(direction) + 1 ) % Direction.values().length];
|
||||
first.getOrCreateTag().putString("Direction", next.name());
|
||||
p_150896_.playSound(SoundEvents.UI_BUTTON_CLICK, 0.5f, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.overrideOtherStackedOnMe(first, second, p_150894_, clickAction, p_150896_, p_150897_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTooltipDetails(@Nullable BasicItem.Key key, ItemStack stack, List<Component> tooltip, boolean advanced) {
|
||||
super.addTooltipDetails(key, stack, tooltip, advanced);
|
||||
if (!stack.hasTag()) return;
|
||||
Item item = stack.getItem();
|
||||
if (item.equals(FunctionalStorage.PULLING_UPGRADE.get()) || item.equals(FunctionalStorage.PUSHING_UPGRADE.get()) || item.equals(FunctionalStorage.COLLECTOR_UPGRADE.get())){
|
||||
tooltip.add(new TextComponent("Direction: ").withStyle(ChatFormatting.GRAY).append(WordUtils.capitalize(stack.getTag().getString("Direction").toLowerCase(Locale.ROOT))));
|
||||
tooltip.add(new TextComponent(""));
|
||||
tooltip.add(new TextComponent("Right click in a GUI to change direction").withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTooltipDetails(@Nullable BasicItem.Key key) {
|
||||
return key == null;
|
||||
}
|
||||
|
||||
public static enum Type{
|
||||
STORAGE,
|
||||
UTILITY
|
||||
|
|
Loading…
Reference in New Issue
Block a user