Compacted drawers

This commit is contained in:
Buuz135 2022-07-08 22:22:09 +02:00
parent c77dae2467
commit 08d3805011
12 changed files with 349 additions and 3 deletions

View File

@ -0,0 +1,34 @@
{
"variants": {
"locked=false,subfacing=north": {
"model": "functionalstorage:block/compacting_framed_drawer"
},
"locked=true,subfacing=north": {
"model": "functionalstorage:block/compacting_framed_drawer_locked"
},
"locked=false,subfacing=south": {
"model": "functionalstorage:block/compacting_framed_drawer",
"y": 180
},
"locked=true,subfacing=south": {
"model": "functionalstorage:block/compacting_framed_drawer_locked",
"y": 180
},
"locked=false,subfacing=west": {
"model": "functionalstorage:block/compacting_framed_drawer",
"y": 270
},
"locked=true,subfacing=west": {
"model": "functionalstorage:block/compacting_framed_drawer_locked",
"y": 270
},
"locked=false,subfacing=east": {
"model": "functionalstorage:block/compacting_framed_drawer",
"y": 90
},
"locked=true,subfacing=east": {
"model": "functionalstorage:block/compacting_framed_drawer_locked",
"y": 90
}
}
}

View File

@ -30,6 +30,7 @@
"block.functionalstorage.framed_1": "Framed Drawer (1x1)",
"block.functionalstorage.framed_2": "Framed Drawer (1x2)",
"block.functionalstorage.framed_4": "Framed Drawer (2x2)",
"block.functionalstorage.compacting_framed_drawer": "Compacting Framed Drawer",
"configurationtool.configmode": "Config Mode: ",
"configurationtool.configmode.locking": "Locking",
"configurationtool.configmode.toggle_numbers": "Hide/Show Amounts",

View File

@ -0,0 +1,6 @@
{
"parent": "functionalstorage:block/compacting_framed_drawer",
"textures": {
"lock_icon": "functionalstorage:blocks/lock"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "functionalstorage:block/compacting_framed_drawer"
}

View File

@ -0,0 +1,3 @@
{
"type": "minecraft:block"
}

View File

@ -2,6 +2,7 @@
"replace": false,
"values": [
"functionalstorage:compacting_drawer",
"functionalstorage:compacting_framed_drawer",
"functionalstorage:storage_controller",
"functionalstorage:armory_cabinet",
"functionalstorage:ender_drawer"

View File

@ -99,6 +99,7 @@ public class FunctionalStorage extends ModuleController {
public static Pair<RegistryObject<Block>, RegistryObject<BlockEntityType<?>>> DRAWER_CONTROLLER;
public static Pair<RegistryObject<Block>, RegistryObject<BlockEntityType<?>>> ARMORY_CABINET;
public static Pair<RegistryObject<Block>, RegistryObject<BlockEntityType<?>>> ENDER_DRAWER;
public static Pair<RegistryObject<Block>, RegistryObject<BlockEntityType<?>>> FRAMED_COMPACTING_DRAWER;
public static RegistryObject<Item> LINKING_TOOL;
public static HashMap<StorageUpgradeItem.StorageTier, RegistryObject<Item>> STORAGE_UPGRADES = new HashMap<>();
@ -144,6 +145,7 @@ public class FunctionalStorage extends ModuleController {
.process(register -> ((RegistryEvent.Register) register).getRegistry()
.registerAll(FramedDrawerRecipe.SERIALIZER.setRegistryName(new ResourceLocation(MOD_ID, "framed_recipe")))).subscribe();
NBTManager.getInstance().scanTileClassForAnnotations(FramedDrawerTile.class);
NBTManager.getInstance().scanTileClassForAnnotations(CompactingFramedDrawerTile.class);
}
@ -164,6 +166,7 @@ public class FunctionalStorage extends ModuleController {
DRAWER_TYPES.get(value).forEach(blockRegistryObject -> TAB.addIconStacks(() -> new ItemStack(blockRegistryObject.getLeft().get())));
}
COMPACTING_DRAWER = getRegistries().registerBlockWithTile("compacting_drawer", () -> new CompactingDrawerBlock("compacting_drawer"));
FRAMED_COMPACTING_DRAWER = getRegistries().registerBlockWithTile("compacting_framed_drawer", () -> new CompactingFramedDrawerBlock("compacting_framed_drawer"));
DRAWER_CONTROLLER = getRegistries().registerBlockWithTile("storage_controller", DrawerControllerBlock::new);
LINKING_TOOL = getRegistries().registerGeneric(Item.class, "linking_tool", LinkingToolItem::new);
for (StorageUpgradeItem.StorageTier value : StorageUpgradeItem.StorageTier.values()) {
@ -215,6 +218,7 @@ public class FunctionalStorage extends ModuleController {
});
}
registerRenderers.registerBlockEntityRenderer((BlockEntityType<? extends CompactingDrawerTile>) COMPACTING_DRAWER.getRight().get(), p_173571_ -> new CompactingDrawerRenderer());
registerRenderers.registerBlockEntityRenderer((BlockEntityType<? extends CompactingDrawerTile>) FRAMED_COMPACTING_DRAWER.getRight().get(), p_173571_ -> new CompactingDrawerRenderer());
registerRenderers.registerBlockEntityRenderer((BlockEntityType<? extends DrawerControllerTile>) DRAWER_CONTROLLER.getRight().get(), p -> new ControllerRenderer());
registerRenderers.registerBlockEntityRenderer((BlockEntityType<? extends EnderDrawerTile>) ENDER_DRAWER.getRight().get(), p_173571_ -> new EnderDrawerRenderer());
}).subscribe();
@ -252,6 +256,7 @@ public class FunctionalStorage extends ModuleController {
}
}
ItemBlockRenderTypes.setRenderLayer(COMPACTING_DRAWER.getLeft().get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(FRAMED_COMPACTING_DRAWER.getLeft().get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(ENDER_DRAWER.getLeft().get(), RenderType.cutout());
}).subscribe();
EventManager.forge(RenderTooltipEvent.Pre.class).process(itemTooltipEvent -> {

View File

@ -0,0 +1,90 @@
package com.buuz135.functionalstorage.block;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.block.tile.CompactingDrawerTile;
import com.buuz135.functionalstorage.block.tile.CompactingFramedDrawerTile;
import com.buuz135.functionalstorage.block.tile.DrawerTile;
import com.buuz135.functionalstorage.block.tile.FramedDrawerTile;
import com.buuz135.functionalstorage.client.model.FramedDrawerModelData;
import com.buuz135.functionalstorage.util.DrawerWoodType;
import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder;
import com.hrznstudio.titanium.util.TileUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.common.Tags;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{
public CompactingFramedDrawerBlock(String name) {
super(name);
}
@Override
public BlockEntityType.BlockEntitySupplier<CompactingDrawerTile> getTileEntityFactory() {
return (blockPos, state) -> new CompactingFramedDrawerTile(this, (BlockEntityType<CompactingDrawerTile>) FunctionalStorage.FRAMED_COMPACTING_DRAWER.getValue().get(), blockPos, state);
}
@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState p_49849_, @Nullable LivingEntity p_49850_, ItemStack stack) {
super.setPlacedBy(level, pos, p_49849_, p_49850_, stack);
TileUtil.getTileEntity(level, pos, CompactingFramedDrawerTile.class).ifPresent(framedDrawerTile -> {
framedDrawerTile.setFramedDrawerModelData(FramedDrawerBlock.getDrawerModelData(stack));
});
}
@Override
public List<ItemStack> getDrops(BlockState p_60537_, LootContext.Builder builder) {
NonNullList<ItemStack> stacks = NonNullList.create();
ItemStack stack = new ItemStack(this);
BlockEntity drawerTile = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (drawerTile instanceof CompactingFramedDrawerTile) {
if (!((CompactingFramedDrawerTile) drawerTile).isEverythingEmpty()) {
stack.getOrCreateTag().put("Tile", drawerTile.saveWithoutMetadata());
}
stack.getOrCreateTag().put("Style", ((CompactingFramedDrawerTile) drawerTile).getFramedDrawerModelData().serializeNBT());
}
stacks.add(stack);
return stacks;
}
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) {
BlockEntity entity = level.getBlockEntity(pos);
if (entity instanceof CompactingFramedDrawerTile framedDrawerTile){
ItemStack stack = new ItemStack(this);
stack.getOrCreateTag().put("Style", framedDrawerTile.getFramedDrawerModelData().serializeNBT());
return stack;
}
return super.getCloneItemStack(state, target, level, pos, player);
}
@Override
public void registerRecipe(Consumer<FinishedRecipe> consumer) {
}
}

View File

@ -319,7 +319,7 @@ public class DrawerBlock extends RotatableBlock<DrawerTile> {
@Override
public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List<net.minecraft.network.chat.Component> tooltip, TooltipFlag p_49819_) {
super.appendHoverText(p_49816_, p_49817_, tooltip, p_49819_);
if (p_49816_.hasTag()) {
if (p_49816_.hasTag() && p_49816_.getTag().contains("Tile")) {
TranslatableComponent text = new TranslatableComponent("drawer.block.contents");
tooltip.add(text.withStyle(ChatFormatting.GRAY));
tooltip.add(new TextComponent(""));

View File

@ -0,0 +1,40 @@
package com.buuz135.functionalstorage.block.tile;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.client.model.FramedDrawerModelData;
import com.hrznstudio.titanium.annotation.Save;
import com.hrznstudio.titanium.block.BasicTileBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import javax.annotation.Nonnull;
import java.util.HashMap;
public class CompactingFramedDrawerTile extends CompactingDrawerTile{
@Save
private FramedDrawerModelData framedDrawerModelData;
public CompactingFramedDrawerTile(BasicTileBlock<CompactingDrawerTile> base, BlockEntityType<CompactingDrawerTile> blockEntityType, BlockPos pos, BlockState state) {
super(base, blockEntityType, pos, state);
this.framedDrawerModelData = new FramedDrawerModelData(new HashMap<>());
}
public FramedDrawerModelData getFramedDrawerModelData() {
return framedDrawerModelData;
}
public void setFramedDrawerModelData(FramedDrawerModelData framedDrawerModelData) {
this.framedDrawerModelData = framedDrawerModelData;
markForUpdate();
if (level.isClientSide) requestModelDataUpdate();
}
@Nonnull
@Override
public IModelData getModelData() {
return new ModelDataMap.Builder().withInitial(FramedDrawerModelData.FRAMED_PROPERTY, framedDrawerModelData).build();
}
}

View File

@ -1,6 +1,7 @@
package com.buuz135.functionalstorage.recipe;
import com.buuz135.functionalstorage.block.CompactingDrawerBlock;
import com.buuz135.functionalstorage.block.FramedDrawerBlock;
import com.google.common.collect.Lists;
import net.minecraft.resources.ResourceLocation;
@ -28,14 +29,19 @@ public class FramedDrawerRecipe extends CustomRecipe {
return !first.isEmpty() && first.getItem() instanceof BlockItem && !second.isEmpty() && second.getItem() instanceof BlockItem && !drawer.isEmpty() && drawer.getItem() instanceof BlockItem && ((BlockItem) drawer.getItem()).getBlock() instanceof FramedDrawerBlock;
}
public static boolean matchesCompacting(ItemStack first, ItemStack second, ItemStack drawer) {
//System.out.println(((BlockItem) drawer.getItem()).getBlock().getClass());
return !first.isEmpty() && first.getItem() instanceof BlockItem && !second.isEmpty() && second.getItem() instanceof BlockItem && !drawer.isEmpty() && drawer.getItem() instanceof BlockItem && ((BlockItem) drawer.getItem()).getBlock() instanceof CompactingDrawerBlock;
}
@Override
public boolean matches(CraftingContainer inv, Level worldIn) {
return matches(inv.getItem(0), inv.getItem(1), inv.getItem(2));
return matches(inv.getItem(0), inv.getItem(1), inv.getItem(2)) || matchesCompacting(inv.getItem(0), inv.getItem(1), inv.getItem(2));
}
@Override
public ItemStack assemble(CraftingContainer inv) {
if (matches(inv.getItem(0), inv.getItem(1), inv.getItem(2))){
if (matches(inv.getItem(0), inv.getItem(1), inv.getItem(2)) || matchesCompacting(inv.getItem(0), inv.getItem(1), inv.getItem(2))){
return FramedDrawerBlock.fill(inv.getItem(0), inv.getItem(1), inv.getItem(2).copy());
}
return ItemStack.EMPTY;

View File

@ -0,0 +1,157 @@
{
"loader": "functionalstorage:framed",
"credit": "Made with Blockbench",
"textures": {
"front": "functionalstorage:blocks/compacting_drawer_front",
"particle": "functionalstorage:blocks/compacting_drawer_side",
"side": "functionalstorage:blocks/compacting_drawer_side",
"lock_icon": "functionalstorage:blocks/unlock"
},
"retextured": [ "particle", "side", "front" ],
"elements": [
{
"from": [9, 1, 0.5],
"to": [15, 7, 2.5],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [1, 9, 7, 15], "texture": "#front"},
"west": {"uv": [0, 0, 2, 6], "texture": "#front"},
"up": {"uv": [0, 0, 6, 2], "texture": "#front"}
}
},
{
"from": [1, 1, 0.5],
"to": [7, 7, 2.5],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [9, 9, 15, 15], "texture": "#front"},
"east": {"uv": [0, 0, 2, 6], "texture": "#front"},
"up": {"uv": [0, 0, 6, 2], "texture": "#front"}
}
},
{
"from": [1, 9, 0.5],
"to": [15, 15, 2.5],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [1, 1, 15, 7], "texture": "#front"},
"down": {"uv": [0, 0, 14, 2], "texture": "#front"}
}
},
{
"from": [15, 1, 0],
"to": [16, 15, 15],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [0, 1, 1, 15], "texture": "#side", "cullface": "north"},
"east": {"uv": [1, 1, 16, 15], "texture": "#side", "cullface": "east"},
"west": {"uv": [0, 1, 15, 15], "texture": "#side"}
}
},
{
"from": [0, 15, 0],
"to": [16, 16, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [0, 0, 16, 1], "texture": "#side", "cullface": "north"},
"east": {"uv": [0, 0, 16, 1], "texture": "#side", "cullface": "east"},
"south": {"uv": [0, 0, 16, 1], "texture": "#side", "cullface": "south"},
"west": {"uv": [0, 0, 16, 1], "texture": "#side", "cullface": "west"},
"up": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "up"},
"down": {"uv": [0, 0, 16, 16], "texture": "#side"}
}
},
{
"from": [0, 1, 0],
"to": [1, 15, 15],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [15, 1, 16, 15], "texture": "#side", "cullface": "north"},
"east": {"uv": [1, 1, 16, 15], "texture": "#side"},
"west": {"uv": [0, 1, 15, 15], "texture": "#side", "cullface": "west"}
}
},
{
"from": [0, 0, 0],
"to": [16, 1, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"north": {"uv": [0, 15, 16, 16], "texture": "#side", "cullface": "north"},
"east": {"uv": [0, 15, 16, 16], "texture": "#side", "cullface": "east"},
"south": {"uv": [0, 15, 16, 16], "texture": "#side", "cullface": "south"},
"west": {"uv": [0, 15, 16, 16], "texture": "#side", "cullface": "west"},
"up": {"uv": [0, 0, 16, 16], "texture": "#side"},
"down": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "down"}
}
},
{
"from": [0, 1, 15],
"to": [16, 15, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]},
"faces": {
"east": {"uv": [0, 1, 1, 15], "texture": "#side", "cullface": "east"},
"south": {"uv": [0, 1, 16, 15], "texture": "#side", "cullface": "south"},
"west": {"uv": [15, 1, 16, 15], "texture": "#side", "cullface": "west"}
}
},
{
"name": "divider",
"from": [1, 7, 0],
"to": [15, 9, 1],
"faces": {
"north": {"uv": [1, 7, 15, 9], "texture": "#side", "cullface": "north"},
"up": {"uv": [15, 8, 1, 7], "texture": "#side"},
"down": {"uv": [15, 8, 1, 9], "texture": "#side"}
}
},
{
"name": "divider",
"from": [7, 1, 0],
"to": [9, 7, 1],
"faces": {
"north": {"uv": [7, 9, 9, 15], "texture": "#side", "cullface": "north"},
"east": {"uv": [7, 9, 8, 15], "texture": "#side"},
"south": {"uv": [0, 0, 2, 6], "texture": "#side"},
"west": {"uv": [8, 9, 9, 15], "texture": "#side"}
}
},
{
"from": [7.5, 15, -0.01],
"to": [8.5, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#lock_icon", "cullface": "north"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 135, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 135, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.25, 0.25, 0.25]
},
"gui": {
"rotation": [30, 225, 0],
"scale": [0.625, 0.625, 0.625]
},
"fixed": {
"scale": [0.5, 0.5, 0.5]
}
}
}