From 9e6a44f3a29f7ee6e24b0925d055a6e12df11c79 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 7 Aug 2022 18:32:02 +0200 Subject: [PATCH] Added redstone upgrade and made cheaper the diamond storage upgrade, closes #7 --- .../assets/functionalstorage/lang/en_us.json | 3 ++ .../models/item/redstone_upgrade.json | 6 +++ .../recipes/diamond_upgrade.json | 2 +- .../recipes/redstone_upgrade.json | 43 +++++++++++++++++++ .../functionalstorage/FunctionalStorage.java | 17 +++++--- .../block/CompactingDrawerBlock.java | 28 ++++++++++++ .../functionalstorage/block/DrawerBlock.java | 34 +++++++++++++-- .../block/EnderDrawerBlock.java | 28 ++++++++++++ .../block/tile/ControllableDrawerTile.java | 12 ++++++ .../data/FunctionalStorageLangProvider.java | 3 ++ .../functionalstorage/item/UpgradeItem.java | 15 +++++++ 11 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 src/generated/resources/assets/functionalstorage/models/item/redstone_upgrade.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/redstone_upgrade.json diff --git a/src/generated/resources/assets/functionalstorage/lang/en_us.json b/src/generated/resources/assets/functionalstorage/lang/en_us.json index 701b46b..1e93b89 100644 --- a/src/generated/resources/assets/functionalstorage/lang/en_us.json +++ b/src/generated/resources/assets/functionalstorage/lang/en_us.json @@ -49,8 +49,11 @@ "item.functionalstorage.puller_upgrade": "Puller Upgrade", "item.functionalstorage.pusher_upgrade": "Pusher Upgrade", "item.functionalstorage.void_upgrade": "Void Upgrade", + "item.functionalstorage.redstone_upgrade": "Redstone Upgrade", "item.utility.direction": "Direction: ", + "item.utility.slot": "Slot: ", "item.utility.direction.desc": "Right click in a GUI to change direction", + "item.utility.slot.desc": "Right click in a GUI to change slot", "item.utility.downgrade": "Downgrades the slots to a max of 64 items", "itemGroup.functionalstorage": "Functional Storage", "key.categories.storage": "Storage", diff --git a/src/generated/resources/assets/functionalstorage/models/item/redstone_upgrade.json b/src/generated/resources/assets/functionalstorage/models/item/redstone_upgrade.json new file mode 100644 index 0000000..23e0b18 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/item/redstone_upgrade.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "functionalstorage:items/redstone_upgrade" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/diamond_upgrade.json b/src/generated/resources/data/functionalstorage/recipes/diamond_upgrade.json index f132342..971c89b 100644 --- a/src/generated/resources/data/functionalstorage/recipes/diamond_upgrade.json +++ b/src/generated/resources/data/functionalstorage/recipes/diamond_upgrade.json @@ -18,7 +18,7 @@ "pattern": [ "IBI", "CDC", - "BBB" + "IBI" ], "key": { "I": { diff --git a/src/generated/resources/data/functionalstorage/recipes/redstone_upgrade.json b/src/generated/resources/data/functionalstorage/recipes/redstone_upgrade.json new file mode 100644 index 0000000..693aea5 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/redstone_upgrade.json @@ -0,0 +1,43 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:redstone_upgrade", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "IBI", + "CDC", + "IBI" + ], + "key": { + "I": { + "item": "minecraft:redstone" + }, + "B": { + "item": "minecraft:redstone_block" + }, + "C": { + "item": "minecraft:comparator" + }, + "D": { + "tag": "functionalstorage:drawer" + } + }, + "result": { + "item": "functionalstorage:redstone_upgrade" + } + } + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index bd3e0f3..cf438be 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -13,10 +13,7 @@ import com.buuz135.functionalstorage.data.FunctionalStorageItemTagsProvider; import com.buuz135.functionalstorage.data.FunctionalStorageLangProvider; import com.buuz135.functionalstorage.inventory.BigInventoryHandler; import com.buuz135.functionalstorage.inventory.item.DrawerStackItemHandler; -import com.buuz135.functionalstorage.item.ConfigurationToolItem; -import com.buuz135.functionalstorage.item.LinkingToolItem; -import com.buuz135.functionalstorage.item.StorageUpgradeItem; -import com.buuz135.functionalstorage.item.UpgradeItem; +import com.buuz135.functionalstorage.item.*; import com.buuz135.functionalstorage.network.EnderDrawerSyncMessage; import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; import com.buuz135.functionalstorage.recipe.FramedDrawerRecipe; @@ -109,6 +106,7 @@ public class FunctionalStorage extends ModuleController { public static RegistryObject PUSHING_UPGRADE; public static RegistryObject VOID_UPGRADE; public static RegistryObject CONFIGURATION_TOOL; + public static RegistryObject REDSTONE_UPGRADE; public static AdvancedTitaniumTab TAB = new AdvancedTitaniumTab("functionalstorage", true); @@ -182,6 +180,7 @@ public class FunctionalStorage extends ModuleController { ARMORY_CABINET = getRegistries().registerBlockWithTile("armory_cabinet", ArmoryCabinetBlock::new); CONFIGURATION_TOOL = getRegistries().registerGeneric(Item.class, "configuration_tool", ConfigurationToolItem::new); ENDER_DRAWER = getRegistries().registerBlockWithTile("ender_drawer", EnderDrawerBlock::new); + REDSTONE_UPGRADE = getRegistries().registerGeneric(Item.class, "redstone_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY)); } public enum DrawerType { @@ -313,6 +312,7 @@ public class FunctionalStorage extends ModuleController { item(PULLING_UPGRADE.get()); item(PUSHING_UPGRADE.get()); item(VOID_UPGRADE.get()); + item(REDSTONE_UPGRADE.get()); } private void item(Item item) { @@ -378,12 +378,19 @@ public class FunctionalStorage extends ModuleController { .define('D', STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.COPPER).get()) .save(consumer); TitaniumShapedRecipeBuilder.shapedRecipe(STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.DIAMOND).get()) - .pattern("IBI").pattern("CDC").pattern("BBB") + .pattern("IBI").pattern("CDC").pattern("IBI") .define('I', Tags.Items.GEMS_DIAMOND) .define('B', Tags.Items.STORAGE_BLOCKS_DIAMOND) .define('C', Tags.Items.CHESTS_WOODEN) .define('D', STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.GOLD).get()) .save(consumer); + TitaniumShapedRecipeBuilder.shapedRecipe(REDSTONE_UPGRADE.get()) + .pattern("IBI").pattern("CDC").pattern("IBI") + .define('I', Items.REDSTONE) + .define('B', Items.REDSTONE_BLOCK) + .define('C', Items.COMPARATOR) + .define('D', StorageTags.DRAWER) + .save(consumer); UpgradeRecipeBuilder.smithing(Ingredient.of(STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.DIAMOND).get()), Ingredient.of(Items.NETHERITE_INGOT), STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.NETHERITE).get()) .unlocks("has_netherite_ingot", has(Items.NETHERITE_INGOT)) .save(consumer, STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.NETHERITE).get().getRegistryName()); diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java index b44cd50..9ad5061 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java @@ -215,4 +215,32 @@ public class CompactingDrawerBlock extends RotatableBlock } super.onRemove(state, worldIn, pos, newState, isMoving); } + + + @Override + public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) { + return true; + } + + @Override + public boolean isSignalSource(BlockState p_60571_) { + return true; + } + + @Override + public int getSignal(BlockState p_60483_, BlockGetter blockGetter, BlockPos blockPos, Direction p_60486_) { + ControllableDrawerTile tile = TileUtil.getTileEntity(blockGetter, blockPos, ControllableDrawerTile.class).orElse(null); + if (tile != null){ + for (int i = 0; i < tile.getUtilityUpgrades().getSlots(); i++) { + ItemStack stack = tile.getUtilityUpgrades().getStackInSlot(i); + if (stack.getItem().equals(FunctionalStorage.REDSTONE_UPGRADE.get())){ + int redstoneSlot = stack.getOrCreateTag().getInt("Slot"); + if (redstoneSlot < tile.getStorage().getSlots()){ + return (int) ((tile.getStorage().getStackInSlot(redstoneSlot).getCount() / (double)tile.getStorage().getSlotLimit(redstoneSlot)) * 15); + } + } + } + } + return 0; + } } diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 3c1e481..e171352 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -1,6 +1,7 @@ package com.buuz135.functionalstorage.block; import com.buuz135.functionalstorage.FunctionalStorage; +import com.buuz135.functionalstorage.block.tile.ControllableDrawerTile; import com.buuz135.functionalstorage.block.tile.DrawerControllerTile; import com.buuz135.functionalstorage.block.tile.DrawerTile; import com.buuz135.functionalstorage.inventory.item.DrawerCapabilityProvider; @@ -24,6 +25,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; @@ -59,10 +61,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -329,6 +328,33 @@ public class DrawerBlock extends RotatableBlock { } } + @Override + public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) { + return true; + } + + @Override + public boolean isSignalSource(BlockState p_60571_) { + return true; + } + + @Override + public int getSignal(BlockState p_60483_, BlockGetter blockGetter, BlockPos blockPos, Direction p_60486_) { + ControllableDrawerTile tile = TileUtil.getTileEntity(blockGetter, blockPos, ControllableDrawerTile.class).orElse(null); + if (tile != null){ + for (int i = 0; i < tile.getUtilityUpgrades().getSlots(); i++) { + ItemStack stack = tile.getUtilityUpgrades().getStackInSlot(i); + if (stack.getItem().equals(FunctionalStorage.REDSTONE_UPGRADE.get())){ + int redstoneSlot = stack.getOrCreateTag().getInt("Slot"); + if (redstoneSlot < tile.getStorage().getSlots()){ + return (int) ((tile.getStorage().getStackInSlot(redstoneSlot).getCount() / (double)tile.getStorage().getSlotLimit(redstoneSlot)) * 15); + } + } + } + } + return 0; + } + public static class DrawerItem extends BlockItem{ private DrawerBlock drawerBlock; diff --git a/src/main/java/com/buuz135/functionalstorage/block/EnderDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/EnderDrawerBlock.java index 8e6eb8e..0c628b0 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/EnderDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/EnderDrawerBlock.java @@ -1,6 +1,7 @@ package com.buuz135.functionalstorage.block; import com.buuz135.functionalstorage.FunctionalStorage; +import com.buuz135.functionalstorage.block.tile.ControllableDrawerTile; import com.buuz135.functionalstorage.block.tile.DrawerControllerTile; import com.buuz135.functionalstorage.block.tile.EnderDrawerTile; import com.buuz135.functionalstorage.item.LinkingToolItem; @@ -183,4 +184,31 @@ public class EnderDrawerBlock extends RotatableBlock { } } + + @Override + public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) { + return true; + } + + @Override + public boolean isSignalSource(BlockState p_60571_) { + return true; + } + + @Override + public int getSignal(BlockState p_60483_, BlockGetter blockGetter, BlockPos blockPos, Direction p_60486_) { + ControllableDrawerTile tile = TileUtil.getTileEntity(blockGetter, blockPos, ControllableDrawerTile.class).orElse(null); + if (tile != null){ + for (int i = 0; i < tile.getUtilityUpgrades().getSlots(); i++) { + ItemStack stack = tile.getUtilityUpgrades().getStackInSlot(i); + if (stack.getItem().equals(FunctionalStorage.REDSTONE_UPGRADE.get())){ + int redstoneSlot = stack.getOrCreateTag().getInt("Slot"); + if (redstoneSlot < tile.getStorage().getSlots()){ + return (int) ((tile.getStorage().getStackInSlot(redstoneSlot).getCount() / (double)tile.getStorage().getSlotLimit(redstoneSlot)) * 15); + } + } + } + } + return 0; + } } diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java index 882ed42..b4e85f7 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java @@ -133,6 +133,18 @@ public abstract class ControllableDrawerTile @Override public void serverTick(Level level, BlockPos pos, BlockState state, T blockEntity) { super.serverTick(level, pos, state, blockEntity); + if (level.getGameTime() % 20 == 0) { + for (int i = 0; i < this.utilityUpgrades.getSlots(); i++) { + ItemStack stack = this.utilityUpgrades.getStackInSlot(i); + if (!stack.isEmpty()) { + Item item = stack.getItem(); + if (item.equals(FunctionalStorage.REDSTONE_UPGRADE.get())) { + level.updateNeighborsAt(this.getBlockPos(), this.getBasicTileBlock()); + break; + } + } + } + } if (level.getGameTime() % 4 == 0) { for (int i = 0; i < this.utilityUpgrades.getSlots(); i++) { ItemStack stack = this.utilityUpgrades.getStackInSlot(i); diff --git a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java index 455546a..ccf4275 100644 --- a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java +++ b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java @@ -51,6 +51,7 @@ public class FunctionalStorageLangProvider extends LanguageProvider { this.add(FunctionalStorage.PULLING_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.PULLING_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) ); this.add(FunctionalStorage.PUSHING_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.PUSHING_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) ); this.add(FunctionalStorage.VOID_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.VOID_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) ); + this.add(FunctionalStorage.REDSTONE_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.REDSTONE_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) ); this.add(FunctionalStorage.ARMORY_CABINET.getLeft().get(), "Armory Cabinet"); this.add(FunctionalStorage.CONFIGURATION_TOOL.get(), "Configuration Tool"); this.add("item.utility.downgrade", "Downgrades the slots to a max of 64 items"); @@ -69,5 +70,7 @@ public class FunctionalStorageLangProvider extends LanguageProvider { this.add("linkingtool.ender.clear", "Sneak + Right Click in the air to clear frequency."); this.add("drawer.block.contents", "Contents: "); this.add("frameddrawer.use", "How 2 Change Texture: \nInside a crafting window place the block you want use the texture of for the outside of the drawer in the first slot of the crafting window, on the second slot put the block that will be used for the texture on the inside of the framed drawer and on the third slot put a framed drawer. \n"); + this.add("item.utility.slot", "Slot: "); + this.add("item.utility.slot.desc", "Right click in a GUI to change slot"); } } diff --git a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java index e71f266..73f6b9f 100644 --- a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java +++ b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java @@ -26,6 +26,7 @@ import java.util.Locale; public class UpgradeItem extends BasicItem { + public static int MAX_SLOT = 4; public static Direction getDirection(ItemStack stack){ if (stack.hasTag()){ @@ -55,6 +56,9 @@ public class UpgradeItem extends BasicItem { 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()); } + if (item.equals(FunctionalStorage.REDSTONE_UPGRADE.get())){ + stack.getOrCreateTag().putInt("Slot", 0); + } return stack; } @@ -81,6 +85,12 @@ public class UpgradeItem extends BasicItem { p_150896_.playSound(SoundEvents.UI_BUTTON_CLICK, 0.5f, 1); return true; } + if (item.equals(FunctionalStorage.REDSTONE_UPGRADE.get())){ + int slot = first.getOrCreateTag().getInt("Slot"); + first.getOrCreateTag().putInt("Slot", (slot + 1) % MAX_SLOT); + p_150896_.playSound(SoundEvents.UI_BUTTON_CLICK, 0.5f, 1); + return true; + } } return super.overrideOtherStackedOnMe(first, second, p_150894_, clickAction, p_150896_, p_150897_); } @@ -95,6 +105,11 @@ public class UpgradeItem extends BasicItem { tooltip.add(new TextComponent("")); tooltip.add(new TranslatableComponent("item.utility.direction.desc").withStyle(ChatFormatting.GRAY)); } + if (item.equals(FunctionalStorage.REDSTONE_UPGRADE.get()) ){ + tooltip.add(new TranslatableComponent("item.utility.slot").withStyle(ChatFormatting.YELLOW).append(new TextComponent(stack.getOrCreateTag().getInt("Slot") + "").withStyle(ChatFormatting.WHITE))); + tooltip.add(new TextComponent("")); + tooltip.add(new TranslatableComponent("item.utility.direction.desc").withStyle(ChatFormatting.GRAY)); + } }