From 8ea488059ae9fa2e06f9dbdd483eb8466549e9b7 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sat, 2 Jul 2022 14:21:23 +0200 Subject: [PATCH 1/7] WIP Framned stuff --- .../block/FramedDrawerBlock.java | 20 + .../block/tile/FramedDrawerTile.java | 14 + .../client/loader/RetexturedModel.java | 267 ++++++++++++ .../client/loader/SimpleBlockModel.java | 412 ++++++++++++++++++ .../client/model/FramedDrawerBlockModel.java | 135 ++++++ .../client/model/FramedDrawerModelData.java | 44 ++ .../models/block/base_framing_x_1_sides.json | 102 +++++ .../models/block/framed_1.json | 10 + 8 files changed, 1004 insertions(+) create mode 100644 src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java create mode 100644 src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerBlockModel.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java create mode 100644 src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json create mode 100644 src/main/resources/assets/functionalstorage/models/block/framed_1.json diff --git a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java new file mode 100644 index 0000000..3811cf5 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java @@ -0,0 +1,20 @@ +package com.buuz135.functionalstorage.block; + +import com.buuz135.functionalstorage.FunctionalStorage; +import com.buuz135.functionalstorage.block.tile.DrawerTile; +import com.buuz135.functionalstorage.util.DrawerWoodType; +import com.buuz135.functionalstorage.util.IWoodType; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.apache.commons.lang3.tuple.Pair; + +public class FramedDrawerBlock extends DrawerBlock{ + + public FramedDrawerBlock(FunctionalStorage.DrawerType type) { + super(DrawerWoodType.FRAMED, type); + } + + @Override + public BlockEntityType.BlockEntitySupplier getTileEntityFactory() { + return (blockPos, state) -> new DrawerTile(this, (BlockEntityType) FunctionalStorage.DRAWER_TYPES.get(this.getType()).stream().filter(registryObjectRegistryObjectPair -> registryObjectRegistryObjectPair.getLeft().get().equals(this)).map(Pair::getRight).findFirst().get().get(), blockPos, state, this.getType()); + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java new file mode 100644 index 0000000..93ec3d6 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java @@ -0,0 +1,14 @@ +package com.buuz135.functionalstorage.block.tile; + +import com.buuz135.functionalstorage.FunctionalStorage; +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; + +public class FramedDrawerTile extends DrawerTile{ + + public FramedDrawerTile(BasicTileBlock base, BlockEntityType blockEntityType, BlockPos pos, BlockState state, FunctionalStorage.DrawerType type) { + super(base, blockEntityType, pos, state, type); + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java new file mode 100644 index 0000000..99b73f3 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java @@ -0,0 +1,267 @@ +package com.buuz135.functionalstorage.client.loader; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; +import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.IModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.geometry.IModelGeometry; + + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/model/RetexturedModel.java} + * + * Model that dynamically retextures a list of textures based on data from {@link RetexturedHelper}. + */ +@SuppressWarnings("WeakerAccess") + +public class RetexturedModel implements IModelGeometry { + private final SimpleBlockModel model; + private final Set retextured; + + @Override + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { + return model.getTextures(owner, modelGetter, missingTextureErrors); + } + + @Override + public BakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation location) { + // bake the model and return + BakedModel baked = model.bakeModel(owner, transform, overrides, spriteGetter, location); + return new Baked(baked, owner, model, transform, getAllRetextured(owner, this.model, retextured)); + } + + /** + * Gets a list of all names to retexture based on the block model texture references + * @param owner Model config instance + * @param model Model fallback + * @param originalSet Original list of names to retexture + * @return Set of textures including parent textures + */ + public static Set getAllRetextured(IModelConfiguration owner, SimpleBlockModel model, Set originalSet) { + Set retextured = Sets.newHashSet(originalSet); + for (Map> textures : ModelTextureIteratable.of(owner, model)) { + textures.forEach((name, either) -> + either.ifRight(parent -> { + if (retextured.contains(parent)) { + retextured.add(name); + } + }) + ); + } + return ImmutableSet.copyOf(retextured); + } + + + /** Registered model loader instance registered */ + public static class Loader implements IModelLoader { + public static final Loader INSTANCE = new Loader(); + private Loader() {} + + @Override + public void onResourceManagerReload(ResourceManager resourceManager) {} + + @Override + public RetexturedModel read(JsonDeserializationContext context, JsonObject json) { + // get base model + SimpleBlockModel model = SimpleBlockModel.deserialize(context, json); + + // get list of textures to retexture + Set retextured = getRetextured(json); + + // return retextured model + return new RetexturedModel(model, retextured); + } + + /** + * Gets the list of retextured textures from the model + * @param json Model json + * @return List of textures + */ + public static Set getRetextured(JsonObject json) { + if (json.has("retextured")) { + // if an array, set from each texture in array + JsonElement retextured = json.get("retextured"); + if (retextured.isJsonArray()) { + JsonArray array = retextured.getAsJsonArray(); + if (array.size() == 0) { + throw new JsonSyntaxException("Must have at least one texture in retextured"); + } + ImmutableSet.Builder builder = ImmutableSet.builder(); + for (int i = 0; i < array.size(); i++) { + builder.add(GsonHelper.convertToString(array.get(i), "retextured[" + i + "]")); + } + return builder.build(); + } + // if string, single texture + if (retextured.isJsonPrimitive()) { + return ImmutableSet.of(retextured.getAsString()); + } + } + // if neither or missing, error + throw new JsonSyntaxException("Missing retextured, expected to find a String or a JsonArray"); + } + } + + /** Baked variant of the model, used to swap out quads based on the texture */ + public static class Baked extends DynamicBakedWrapper { + /** Cache of texture name to baked model */ + private final Map cache = new ConcurrentHashMap<>(); + /* Properties for rebaking */ + private final IModelConfiguration owner; + private final SimpleBlockModel model; + private final ModelState transform; + /** List of texture names that are retextured */ + private final Set retextured; + + public Baked(BakedModel baked, IModelConfiguration owner, SimpleBlockModel model, ModelState transform, Set retextured) { + super(baked); + this.model = model; + this.owner = owner; + this.transform = transform; + this.retextured = retextured; + } + + /** + * Gets the model with the given texture applied + * @param name Texture location + * @return Retextured model + */ + private BakedModel getRetexturedModel(ResourceLocation name) { + return model.bakeDynamic(new RetexturedConfiguration(owner, retextured, name), transform); + } + + /** + * Gets a cached retextured model, computing it if missing from the cache + * @param block Block determining the texture + * @return Retextured model + */ + private BakedModel getCachedModel(Block block) { + return cache.computeIfAbsent(ModelHelper.getParticleTexture(block), this::getRetexturedModel); + } + + @Override + public TextureAtlasSprite getParticleIcon(IModelData data) { + // if particle is retextured, fetch particle from the cached model + if (retextured.contains("particle")) { + Block block = data.getData(RetexturedHelper.BLOCK_PROPERTY); + if (block != null) { + return getCachedModel(block).getParticleIcon(data); + } + } + return originalModel.getParticleIcon(data); + } + + @Nonnull + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction direction, Random random, IModelData data) { + Block block = data.getData(RetexturedHelper.BLOCK_PROPERTY); + if (block == null) { + return originalModel.getQuads(state, direction, random, data); + } + return getCachedModel(block).getQuads(state, direction, random, data); + } + + @Override + public ItemOverrides getOverrides() { + return RetexturedOverride.INSTANCE; + } + } + + /** + * Model configuration wrapper to retexture the block + */ + public static class RetexturedConfiguration extends ModelConfigurationWrapper { + /** List of textures to retexture */ + private final Set retextured; + /** Replacement texture */ + private final Material texture; + + /** + * Creates a new configuration wrapper + * @param base Original model configuration + * @param retextured Set of textures that should be retextured + * @param texture New texture to replace those in the set + */ + public RetexturedConfiguration(IModelConfiguration base, Set retextured, ResourceLocation texture) { + super(base); + this.retextured = retextured; + this.texture = ModelLoaderRegistry.blockMaterial(texture); + } + + @Override + public boolean isTexturePresent(String name) { + if (retextured.contains(name)) { + return !MissingTextureAtlasSprite.getLocation().equals(texture.texture()); + } + return super.isTexturePresent(name); + } + + @Override + public Material resolveTexture(String name) { + if (retextured.contains(name)) { + return texture; + } + return super.resolveTexture(name); + } + } + + /** Override list to swap the texture in from NBT */ + private static class RetexturedOverride extends ItemOverrides { + private static final RetexturedOverride INSTANCE = new RetexturedOverride(); + + @Nullable + @Override + public BakedModel resolve(BakedModel originalModel, ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int pSeed) { + if (stack.isEmpty() || !stack.hasTag()) { + return originalModel; + } + + // get the block first, ensuring its valid + Block block = RetexturedBlockItem.getTexture(stack); + if (block == Blocks.AIR) { + return originalModel; + } + + // if valid, use the block + return ((Baked)originalModel).getCachedModel(block); + } + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java b/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java new file mode 100644 index 0000000..99777bc --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java @@ -0,0 +1,412 @@ +package com.buuz135.functionalstorage.client.loader; + +import com.buuz135.functionalstorage.FunctionalStorage; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; +import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.util.Pair; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.BlockElement; +import net.minecraft.client.renderer.block.model.BlockElementFace; +import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.SimpleBakedModel; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraftforge.client.model.ForgeModelBakery; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.IModelLoader; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Simplier version of {@link BlockModel} for use in an {@link net.minecraftforge.client.model.IModelLoader}, as the owner handles most block model properties + */ +@SuppressWarnings("WeakerAccess") +public class SimpleBlockModel implements IModelGeometry { + /** + * Model loader for vanilla block model, mainly intended for use in fallback registration + */ + public static final Loader LOADER = new Loader(); + /** + * Location used for baking dynamic models, name does not matter so just using a constant + */ + private static final ResourceLocation BAKE_LOCATION = new ResourceLocation(FunctionalStorage.MOD_ID, "dynamic_model_baking"); + + /** + * Parent model location, used to fetch parts and for textures if the owner is not a block model + */ + + @Nullable + private ResourceLocation parentLocation; + /** + * Model parts for baked model, if empty uses parent parts + */ + private final List parts; + /** + * Fallback textures in case the owner does not contain a block model + */ + private final Map> textures; + + private BlockModel parent; + + /** + * Creates a new simple block model + * + * @param parentLocation Location of the parent model, if unset has no parent + * @param textures List of textures for iteration, in case the owner is not BlockModel + * @param parts List of parts in the model + */ + public SimpleBlockModel(@Nullable ResourceLocation parentLocation, Map> textures, List parts) { + this.parts = parts; + this.textures = textures; + this.parentLocation = parentLocation; + } + + + /* Properties */ + + /** + * Gets the elements in this simple block model + * + * @return Elements in the model + */ + @SuppressWarnings("deprecation") + public List getElements() { + return parts.isEmpty() && parent != null ? parent.getElements() : parts; + } + + /* Textures */ + + /** + * Fetches parent models for this model and its parents + * + * @param modelGetter Model getter function + */ + public void fetchParent(IModelConfiguration owner, Function modelGetter) { + // no work if no parent or the parent is fetched already + if (parent != null || parentLocation == null) { + return; + } + + // iterate through model parents + Set chain = Sets.newLinkedHashSet(); + + // load the first model directly + parent = getParent(modelGetter, chain, parentLocation, owner.getModelName()); + // null means no model, so set missing + if (parent == null) { + parent = getMissing(modelGetter); + parentLocation = ModelBakery.MISSING_MODEL_LOCATION; + } + + // loop through each parent, adding in parents + for (BlockModel link = parent; link.parentLocation != null && link.parent == null; link = link.parent) { + chain.add(link); + + // fetch model parent + link.parent = getParent(modelGetter, chain, link.parentLocation, link.name); + + // null means no model, so set missing + if (link.parent == null) { + link.parent = getMissing(modelGetter); + link.parentLocation = ModelBakery.MISSING_MODEL_LOCATION; + } + } + } + + /** + * Gets the parent for a model + * + * @param modelGetter Model getter function + * @param chain Chain of models that are in progress + * @param location Location to fetch + * @param name Name of the model being fetched + * @return Block model instance, null if there was an error + */ + @Nullable + private static BlockModel getParent(Function modelGetter, Set chain, ResourceLocation location, String name) { + // model must exist + UnbakedModel unbaked = modelGetter.apply(location); + if (unbaked == null) { + FunctionalStorage.LOGGER.warn("No parent '{}' while loading model '{}'", location, name); + return null; + } + // no loops in chain + if (chain.contains(unbaked)) { + FunctionalStorage.LOGGER.warn("Found 'parent' loop while loading model '{}' in chain: {} -> {}", name, chain.stream().map(Object::toString).collect(Collectors.joining(" -> ")), location); + return null; + } + // model must be block model, this is a serious error in vanilla + if (!(unbaked instanceof BlockModel)) { + throw new IllegalStateException("BlockModel parent has to be a block model."); + } + return (BlockModel) unbaked; + } + + /** + * Gets the missing model, ensuring its the right type + * + * @param modelGetter Model getter function + * @return Missing model as a {@link BlockModel} + */ + @Nonnull + private static BlockModel getMissing(Function modelGetter) { + UnbakedModel model = modelGetter.apply(ModelBakery.MISSING_MODEL_LOCATION); + if (!(model instanceof BlockModel)) { + throw new IllegalStateException("Failed to load missing model"); + } + return (BlockModel) model; + } + + /** + * Gets the texture dependencies for a list of elements, allows calling outside a simple block model + * + * @param owner Model configuration + * @param elements List of elements to check for textures + * @param missingTextureErrors Missing texture set + * @return Textures dependencies + */ + public static Collection getTextures(IModelConfiguration owner, List elements, Set> missingTextureErrors) { + // always need a particle texture + Set textures = Sets.newHashSet(owner.resolveTexture("particle")); + // iterate all elements, fetching needed textures from the material + for (BlockElement part : elements) { + for (BlockElementFace face : part.faces.values()) { + Material material = owner.resolveTexture(face.texture); + if (Objects.equals(material.texture(), MissingTextureAtlasSprite.getLocation())) { + missingTextureErrors.add(Pair.of(face.texture, owner.getModelName())); + } + textures.add(material); + } + } + return textures; + } + + /** + * Gets the texture and model dependencies for a block model + * + * @param owner Model configuration + * @param modelGetter Model getter to fetch parent models + * @param missingTextureErrors Missing texture set + * @return Textures dependencies + */ + @Override + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { + this.fetchParent(owner, modelGetter); + return getTextures(owner, getElements(), missingTextureErrors); + } + + + /* Baking */ + + /** + * Bakes a single part of the model into the builder + * + * @param builder Baked model builder + * @param owner Model owner + * @param part Part to bake + * @param transform Model transforms + * @param spriteGetter Sprite getter + * @param location Model location + */ + public static void bakePart(SimpleBakedModel.Builder builder, IModelConfiguration owner, BlockElement part, ModelState transform, Function spriteGetter, ResourceLocation location) { + for (Direction direction : part.faces.keySet()) { + BlockElementFace face = part.faces.get(direction); + // ensure the name is not prefixed (it always is) + String texture = face.texture; + if (texture.charAt(0) == '#') { + texture = texture.substring(1); + } + // bake the face + TextureAtlasSprite sprite = spriteGetter.apply(owner.resolveTexture(texture)); + BakedQuad bakedQuad = BlockModel.makeBakedQuad(part, face, sprite, direction, transform, location); + // apply cull face + if (face.cullForDirection == null) { + builder.addUnculledFace(bakedQuad); + } else { + builder.addCulledFace(Direction.rotate(transform.getRotation().getMatrix(), face.cullForDirection), bakedQuad); + } + } + } + + /** + * Bakes a list of block part elements into a model + * + * @param owner Model configuration + * @param elements Model elements + * @param transform Model transform + * @param overrides Model overrides + * @param spriteGetter Sprite getter instance + * @param location Model bake location + * @return Baked model + */ + public static BakedModel bakeModel(IModelConfiguration owner, List elements, ModelState transform, ItemOverrides overrides, Function spriteGetter, ResourceLocation location) { + // iterate parts, adding to the builder + TextureAtlasSprite particle = spriteGetter.apply(owner.resolveTexture("particle")); + SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(owner, overrides).particle(particle); + for (BlockElement part : elements) { + bakePart(builder, owner, part, transform, spriteGetter, location); + } + return builder.build(); + } + + /** + * Same as {@link #bakeModel(IModelConfiguration, List, ModelState, ItemOverrides, Function, ResourceLocation)}, but passes in sensible defaults for values unneeded in dynamic models + * + * @param owner Model configuration + * @param elements Elements to bake + * @param transform Model transform + * @return Baked model + */ + public static BakedModel bakeDynamic(IModelConfiguration owner, List elements, ModelState transform) { + return bakeModel(owner, elements, transform, ItemOverrides.EMPTY, ForgeModelBakery.defaultTextureGetter(), BAKE_LOCATION); + } + + /** + * Bakes the given block model + * + * @param owner Model configuration + * @param transform Transform to apply + * @param overrides Item overrides in baking + * @param spriteGetter Sprite getter instance + * @param location Bake location + * @return Baked model + */ + public BakedModel bakeModel(IModelConfiguration owner, ModelState transform, ItemOverrides overrides, Function spriteGetter, ResourceLocation location) { + return bakeModel(owner, this.getElements(), transform, overrides, spriteGetter, location); + } + + @Override + public BakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation location) { + return bakeModel(owner, transform, overrides, spriteGetter, location); + } + + /** + * Same as {@link #bakeModel(IModelConfiguration, ModelState, ItemOverrides, Function, ResourceLocation)}, but passes in sensible defaults for values unneeded in dynamic models + * + * @param owner Model configuration + * @param transform Transform to apply + * @return Baked model + */ + public BakedModel bakeDynamic(IModelConfiguration owner, ModelState transform) { + return bakeDynamic(owner, this.getElements(), transform); + } + + + /* Deserializing */ + + /** + * Deserializes a SimpleBlockModel from JSON + * + * @param context Json Context + * @param json Json element containing the model + * @return Serialized JSON + */ + public static SimpleBlockModel deserialize(JsonDeserializationContext context, JsonObject json) { + // parent, null if missing + String parentName = GsonHelper.getAsString(json, "parent", ""); + ResourceLocation parent = parentName.isEmpty() ? null : new ResourceLocation(parentName); + + // textures, empty map if missing + Map> textureMap; + if (json.has("textures")) { + ImmutableMap.Builder> builder = new ImmutableMap.Builder<>(); + ResourceLocation atlas = InventoryMenu.BLOCK_ATLAS; + JsonObject textures = GsonHelper.getAsJsonObject(json, "textures"); + for (Entry entry : textures.entrySet()) { + builder.put(entry.getKey(), BlockModel.Deserializer.parseTextureLocationOrReference(atlas, entry.getValue().getAsString())); + } + textureMap = builder.build(); + } else { + textureMap = Collections.emptyMap(); + } + + // elements, empty list if missing + List parts; + if (json.has("elements")) { + parts = getModelElements(context, GsonHelper.getAsJsonArray(json, "elements"), "elements"); + } else { + parts = Collections.emptyList(); + } + return new SimpleBlockModel(parent, textureMap, parts); + } + + /** + * Gets a list of models from a JSON array + * + * @param context Json Context + * @param array Json array + * @return Model list + */ + public static List getModelElements(JsonDeserializationContext context, JsonElement array, String name) { + // if just one element, array is optional + if (array.isJsonObject()) { + return ImmutableList.of(context.deserialize(array.getAsJsonObject(), BlockElement.class)); + } + // if an array, get array of elements + if (array.isJsonArray()) { + ImmutableList.Builder builder = ImmutableList.builder(); + for (JsonElement json : array.getAsJsonArray()) { + builder.add((BlockElement) context.deserialize(json, BlockElement.class)); + } + return builder.build(); + } + + throw new JsonSyntaxException("Missing " + name + ", expected to find a JsonArray or JsonObject"); + } + + /** + * Logic to implement a vanilla block model + */ + private static class Loader implements IModelLoader { + @Override + public void onResourceManagerReload(ResourceManager resourceManager) { + } + + @Override + public SimpleBlockModel read(JsonDeserializationContext context, JsonObject json) { + return deserialize(context, json); + } + } + + @Nullable + public ResourceLocation getParentLocation() { + return parentLocation; + } + + public Map> getTextures() { + return textures; + } + + public BlockModel getParent() { + return parent; + } +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerBlockModel.java b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerBlockModel.java new file mode 100644 index 0000000..289513f --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerBlockModel.java @@ -0,0 +1,135 @@ +/* + * This file is part of Industrial Foregoing. + * + * Copyright 2021, Buuz135 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the + * Software without restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the + * following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.buuz135.functionalstorage.client.model; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; +import org.apache.commons.lang3.tuple.Pair; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.*; + +public class FramedDrawerBlockModel implements IDynamicBakedModel { + + public static Cache>, Direction>, List> CACHE = CacheBuilder.newBuilder().build(); + private VertexFormat format; + private BakedModel previousModel; + private Map> prevQuads = new HashMap<>(); + + public FramedDrawerBlockModel(BakedModel previousConveyor) { + this.previousModel = previousConveyor; + this.format = DefaultVertexFormat.BLOCK; + } + + @Nonnull + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { + List bakedQuads = new ArrayList<>(); + BakedModel otherModel = Minecraft.getInstance().getBlockRenderer().getBlockModel(Blocks.STONE.defaultBlockState()); + for (BakedQuad quad : previousModel.getQuads(state, side, rand)) { + if (otherModel.getQuads(state, side, rand).size() > 0) { + BakedQuadBuilder bakedQuadBuilder = new BakedQuadBuilder(otherModel.getQuads(state, side, rand).get(0).getSprite()); + bakedQuadBuilder.setQuadOrientation(quad.getDirection()); + bakedQuadBuilder.setQuadTint(quad.getTintIndex()); + bakedQuadBuilder.setApplyDiffuseLighting(quad.isShade()); + quad.pipe(bakedQuadBuilder); + + bakedQuadBuilder.setTexture(otherModel.getQuads(state, side, rand).get(0).getSprite()); + System.out.println(otherModel.getQuads(state, side, rand).get(0).getVertices().length); + BakedQuad extra = bakedQuadBuilder.build(); + System.out.println(Arrays.toString(extra.getVertices())); + bakedQuads.add(extra); + //bakedQuadBuilder.getVertexFormat() + //bakedQuads.add(bakedQuadBuilder.build()); + } + } + return bakedQuads;/* + if (state == null) { + if (!prevQuads.containsKey(side)) + prevQuads.put(side, previousModel.getQuads(state, side, rand)); + return prevQuads.get(side); + } + if (!prevQuads.containsKey(side)) + prevQuads.put(side, previousModel.getQuads(state, side, rand)); + List quads = new ArrayList<>(prevQuads.get(side)); + return quads;*/ + } + + @Override + public boolean useAmbientOcclusion() { + return previousModel.useAmbientOcclusion(); + } + + @Override + public boolean isGui3d() { + return previousModel.isGui3d(); + } + + @Override + public boolean usesBlockLight() { + return previousModel.usesBlockLight(); + } + + @Override + public boolean isCustomRenderer() { + return previousModel.isCustomRenderer(); + } + + @Nonnull + @Override + public TextureAtlasSprite getParticleIcon() { + return previousModel.getParticleIcon(); + } + + @Nonnull + @Override + public ItemOverrides getOverrides() { + return previousModel.getOverrides(); + } + + @Override + public BakedModel handlePerspective(ItemTransforms.TransformType cameraTransformType, PoseStack mat) { + return previousModel.handlePerspective(cameraTransformType, mat); + } + + @Override + public ItemTransforms getTransforms() { + return previousModel.getTransforms(); + } +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java new file mode 100644 index 0000000..876309a --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java @@ -0,0 +1,44 @@ +/* + * This file is part of Industrial Foregoing. + * + * Copyright 2021, Buuz135 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the + * Software without restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the + * following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.buuz135.functionalstorage.client.model; + + +import net.minecraft.core.Direction; +import net.minecraft.world.item.Item; +import net.minecraftforge.client.model.data.ModelProperty; + +import java.util.Map; + +public class FramedDrawerModelData { + + public static final ModelProperty UPGRADE_PROPERTY = new ModelProperty<>(); + private Map design; + + public FramedDrawerModelData(Map design) { + this.design = design; + } + + public Map getDesign() { + return design; + } +} diff --git a/src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json b/src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json new file mode 100644 index 0000000..ac9f872 --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json @@ -0,0 +1,102 @@ +{ + "credit": "Made with Blockbench", + "textures": { + "lock_icon": "functionalstorage:blocks/unlock" + }, + "elements": [ + { + "from": [15, 1, 0], + "to": [16, 15, 15], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 15, 15, 16], "rotation": 90, "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, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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": [1, 15, 15, 16], "rotation": 90, "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, 0, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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"}, + "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": [1, 0, 15, 1], "rotation": 90, "texture": "#side", "cullface": "east"}, + "south": {"uv": [0, 1, 16, 15], "texture": "#side", "cullface": "south"}, + "west": {"uv": [1, 15, 15, 16], "rotation": 90, "texture": "#side", "cullface": "west"} + } + }, + { + "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, 45, 0], + "scale": [0.4, 0.4, 0.4] + }, + "firstperson_lefthand": { + "rotation": [0, 225, 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] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_1.json b/src/main/resources/assets/functionalstorage/models/block/framed_1.json new file mode 100644 index 0000000..3452687 --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/framed_1.json @@ -0,0 +1,10 @@ +{ + "loader": "functionalstorage:framed", + "parent": "functionalstorage:block/base_x_1", + "textures": { + "particle": "functionalstorage:blocks/acacia_front_1", + "front": "functionalstorage:blocks/acacia_front_1", + "side": "functionalstorage:blocks/acacia_side" + }, + "retextured": [ "particle", "side" ] +} \ No newline at end of file From 302842c7980f72e6c9cd658cd98f57e5c8ecd0a4 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 3 Jul 2022 20:11:34 +0200 Subject: [PATCH 2/7] Most of framed drawer stuff --- build.gradle | 2 +- .../blockstates/framed_1.json | 34 +++ .../blockstates/framed_2.json | 34 +++ .../blockstates/framed_4.json | 34 +++ .../assets/functionalstorage/lang/en_us.json | 3 + .../models/block/framed_1_locked.json | 6 + .../models/block/framed_2_locked.json | 6 + .../models/block/framed_4_locked.json | 6 + .../models/item/framed_1.json | 3 + .../models/item/framed_2.json | 3 + .../models/item/framed_4.json | 3 + .../functionalstorage/FunctionalStorage.java | 28 ++- .../block/FramedDrawerBlock.java | 88 +++++++- .../block/tile/FramedDrawerTile.java | 27 +++ .../client/loader/DynamicBakedWrapper.java | 40 ++++ .../loader/ModelConfigurationWrapper.java | 79 +++++++ .../client/loader/ModelHelper.java | 210 ++++++++++++++++++ .../client/loader/ModelTextureIteratable.java | 91 ++++++++ .../client/loader/RetexturedHelper.java | 70 ++++++ .../client/loader/RetexturedModel.java | 64 +++--- .../client/loader/SimpleBlockModel.java | 4 +- .../client/model/FramedDrawerModelData.java | 46 +++- .../recipe/FramedDrawerRecipe.java | 53 +++++ .../util/DrawerWoodType.java | 3 +- .../resources/META-INF/accesstransformer.cfg | 8 +- ...ng_x_1_sides.json => base_x_2_framed.json} | 45 +++- .../models/block/base_x_4_framed.json | 175 +++++++++++++++ .../models/block/framed_1.json | 6 +- .../models/block/framed_2.json | 8 + .../models/block/framed_4.json | 8 + .../functionalstorage/recipes/framed.json | 3 + 31 files changed, 1130 insertions(+), 60 deletions(-) create mode 100644 src/generated/resources/assets/functionalstorage/blockstates/framed_1.json create mode 100644 src/generated/resources/assets/functionalstorage/blockstates/framed_2.json create mode 100644 src/generated/resources/assets/functionalstorage/blockstates/framed_4.json create mode 100644 src/generated/resources/assets/functionalstorage/models/block/framed_1_locked.json create mode 100644 src/generated/resources/assets/functionalstorage/models/block/framed_2_locked.json create mode 100644 src/generated/resources/assets/functionalstorage/models/block/framed_4_locked.json create mode 100644 src/generated/resources/assets/functionalstorage/models/item/framed_1.json create mode 100644 src/generated/resources/assets/functionalstorage/models/item/framed_2.json create mode 100644 src/generated/resources/assets/functionalstorage/models/item/framed_4.json create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/DynamicBakedWrapper.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/ModelConfigurationWrapper.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/ModelHelper.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/ModelTextureIteratable.java create mode 100644 src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedHelper.java create mode 100644 src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java rename src/main/resources/assets/functionalstorage/models/block/{base_framing_x_1_sides.json => base_x_2_framed.json} (79%) create mode 100644 src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json create mode 100644 src/main/resources/assets/functionalstorage/models/block/framed_2.json create mode 100644 src/main/resources/assets/functionalstorage/models/block/framed_4.json create mode 100644 src/main/resources/data/functionalstorage/recipes/framed.json diff --git a/build.gradle b/build.gradle index a826bc2..aef383d 100644 --- a/build.gradle +++ b/build.gradle @@ -91,7 +91,7 @@ repositories { dependencies { - minecraft 'net.minecraftforge:forge:1.18.2-40.1.18' + minecraft 'net.minecraftforge:forge:1.18.2-40.1.19' implementation fg.deobf (project.dependencies.create('com.hrznstudio:titanium:1.18.2-3.5.6-38')) compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.7.0.180:api") runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.7.0.180") diff --git a/src/generated/resources/assets/functionalstorage/blockstates/framed_1.json b/src/generated/resources/assets/functionalstorage/blockstates/framed_1.json new file mode 100644 index 0000000..45d6d00 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/blockstates/framed_1.json @@ -0,0 +1,34 @@ +{ + "variants": { + "locked=false,subfacing=north": { + "model": "functionalstorage:block/framed_1" + }, + "locked=true,subfacing=north": { + "model": "functionalstorage:block/framed_1_locked" + }, + "locked=false,subfacing=south": { + "model": "functionalstorage:block/framed_1", + "y": 180 + }, + "locked=true,subfacing=south": { + "model": "functionalstorage:block/framed_1_locked", + "y": 180 + }, + "locked=false,subfacing=west": { + "model": "functionalstorage:block/framed_1", + "y": 270 + }, + "locked=true,subfacing=west": { + "model": "functionalstorage:block/framed_1_locked", + "y": 270 + }, + "locked=false,subfacing=east": { + "model": "functionalstorage:block/framed_1", + "y": 90 + }, + "locked=true,subfacing=east": { + "model": "functionalstorage:block/framed_1_locked", + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/blockstates/framed_2.json b/src/generated/resources/assets/functionalstorage/blockstates/framed_2.json new file mode 100644 index 0000000..d786d1c --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/blockstates/framed_2.json @@ -0,0 +1,34 @@ +{ + "variants": { + "locked=false,subfacing=north": { + "model": "functionalstorage:block/framed_2" + }, + "locked=true,subfacing=north": { + "model": "functionalstorage:block/framed_2_locked" + }, + "locked=false,subfacing=south": { + "model": "functionalstorage:block/framed_2", + "y": 180 + }, + "locked=true,subfacing=south": { + "model": "functionalstorage:block/framed_2_locked", + "y": 180 + }, + "locked=false,subfacing=west": { + "model": "functionalstorage:block/framed_2", + "y": 270 + }, + "locked=true,subfacing=west": { + "model": "functionalstorage:block/framed_2_locked", + "y": 270 + }, + "locked=false,subfacing=east": { + "model": "functionalstorage:block/framed_2", + "y": 90 + }, + "locked=true,subfacing=east": { + "model": "functionalstorage:block/framed_2_locked", + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/blockstates/framed_4.json b/src/generated/resources/assets/functionalstorage/blockstates/framed_4.json new file mode 100644 index 0000000..3226cad --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/blockstates/framed_4.json @@ -0,0 +1,34 @@ +{ + "variants": { + "locked=false,subfacing=north": { + "model": "functionalstorage:block/framed_4" + }, + "locked=true,subfacing=north": { + "model": "functionalstorage:block/framed_4_locked" + }, + "locked=false,subfacing=south": { + "model": "functionalstorage:block/framed_4", + "y": 180 + }, + "locked=true,subfacing=south": { + "model": "functionalstorage:block/framed_4_locked", + "y": 180 + }, + "locked=false,subfacing=west": { + "model": "functionalstorage:block/framed_4", + "y": 270 + }, + "locked=true,subfacing=west": { + "model": "functionalstorage:block/framed_4_locked", + "y": 270 + }, + "locked=false,subfacing=east": { + "model": "functionalstorage:block/framed_4", + "y": 90 + }, + "locked=true,subfacing=east": { + "model": "functionalstorage:block/framed_4_locked", + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/lang/en_us.json b/src/generated/resources/assets/functionalstorage/lang/en_us.json index 2da1184..7be8a66 100644 --- a/src/generated/resources/assets/functionalstorage/lang/en_us.json +++ b/src/generated/resources/assets/functionalstorage/lang/en_us.json @@ -27,6 +27,9 @@ "block.functionalstorage.warped_1": "Warped Drawer (1x1)", "block.functionalstorage.warped_2": "Warped Drawer (1x2)", "block.functionalstorage.warped_4": "Warped Drawer (2x2)", + "block.functionalstorage.framed_1": "Framed Drawer (1x1)", + "block.functionalstorage.framed_2": "Framed Drawer (1x2)", + "block.functionalstorage.framed_4": "Framed Drawer (2x2)", "configurationtool.configmode": "Config Mode: ", "configurationtool.configmode.locking": "Locking", "configurationtool.configmode.toggle_numbers": "Hide/Show Amounts", diff --git a/src/generated/resources/assets/functionalstorage/models/block/framed_1_locked.json b/src/generated/resources/assets/functionalstorage/models/block/framed_1_locked.json new file mode 100644 index 0000000..6346d27 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/block/framed_1_locked.json @@ -0,0 +1,6 @@ +{ + "parent": "functionalstorage:block/framed_1", + "textures": { + "lock_icon": "functionalstorage:blocks/lock" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/block/framed_2_locked.json b/src/generated/resources/assets/functionalstorage/models/block/framed_2_locked.json new file mode 100644 index 0000000..f039cf1 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/block/framed_2_locked.json @@ -0,0 +1,6 @@ +{ + "parent": "functionalstorage:block/framed_2", + "textures": { + "lock_icon": "functionalstorage:blocks/lock" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/block/framed_4_locked.json b/src/generated/resources/assets/functionalstorage/models/block/framed_4_locked.json new file mode 100644 index 0000000..9ac9598 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/block/framed_4_locked.json @@ -0,0 +1,6 @@ +{ + "parent": "functionalstorage:block/framed_4", + "textures": { + "lock_icon": "functionalstorage:blocks/lock" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/item/framed_1.json b/src/generated/resources/assets/functionalstorage/models/item/framed_1.json new file mode 100644 index 0000000..bac28e9 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/item/framed_1.json @@ -0,0 +1,3 @@ +{ + "parent": "functionalstorage:block/framed_1" +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/item/framed_2.json b/src/generated/resources/assets/functionalstorage/models/item/framed_2.json new file mode 100644 index 0000000..9585ba6 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/item/framed_2.json @@ -0,0 +1,3 @@ +{ + "parent": "functionalstorage:block/framed_2" +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/item/framed_4.json b/src/generated/resources/assets/functionalstorage/models/item/framed_4.json new file mode 100644 index 0000000..906e0ec --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/item/framed_4.json @@ -0,0 +1,3 @@ +{ + "parent": "functionalstorage:block/framed_4" +} \ 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 a283f1c..15a59af 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -1,14 +1,12 @@ package com.buuz135.functionalstorage; import com.buuz135.functionalstorage.block.*; -import com.buuz135.functionalstorage.block.tile.CompactingDrawerTile; -import com.buuz135.functionalstorage.block.tile.DrawerControllerTile; -import com.buuz135.functionalstorage.block.tile.DrawerTile; -import com.buuz135.functionalstorage.block.tile.EnderDrawerTile; +import com.buuz135.functionalstorage.block.tile.*; import com.buuz135.functionalstorage.client.CompactingDrawerRenderer; import com.buuz135.functionalstorage.client.ControllerRenderer; import com.buuz135.functionalstorage.client.DrawerRenderer; import com.buuz135.functionalstorage.client.EnderDrawerRenderer; +import com.buuz135.functionalstorage.client.loader.RetexturedModel; import com.buuz135.functionalstorage.data.FunctionalStorageBlockTagsProvider; import com.buuz135.functionalstorage.data.FunctionalStorageBlockstateProvider; import com.buuz135.functionalstorage.data.FunctionalStorageItemTagsProvider; @@ -21,6 +19,7 @@ import com.buuz135.functionalstorage.item.StorageUpgradeItem; import com.buuz135.functionalstorage.item.UpgradeItem; import com.buuz135.functionalstorage.network.EnderDrawerSyncMessage; import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; +import com.buuz135.functionalstorage.recipe.FramedDrawerRecipe; import com.buuz135.functionalstorage.util.*; import com.hrznstudio.titanium.block.BasicBlock; import com.hrznstudio.titanium.block.BasicTileBlock; @@ -28,6 +27,7 @@ import com.hrznstudio.titanium.datagenerator.loot.TitaniumLootTableProvider; import com.hrznstudio.titanium.datagenerator.model.BlockItemModelGeneratorProvider; import com.hrznstudio.titanium.event.handler.EventManager; import com.hrznstudio.titanium.module.ModuleController; +import com.hrznstudio.titanium.nbthandler.NBTManager; import com.hrznstudio.titanium.network.NetworkHandler; import com.hrznstudio.titanium.recipe.generator.TitaniumRecipeProvider; import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; @@ -51,7 +51,9 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.client.event.EntityRenderersEvent; +import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.RenderTooltipEvent; +import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.generators.BlockModelProvider; import net.minecraftforge.client.model.generators.ItemModelProvider; import net.minecraftforge.common.Tags; @@ -88,7 +90,7 @@ public class FunctionalStorage extends ModuleController { } // Directly reference a log4j logger. - private static final Logger LOGGER = LogManager.getLogger(); + public static final Logger LOGGER = LogManager.getLogger(); public static List WOOD_TYPES = new ArrayList<>(); @@ -138,6 +140,10 @@ public class FunctionalStorage extends ModuleController { EventManager.modGeneric(RegistryEvent.Register.class, RecipeSerializer.class).process(register -> { CraftingHelper.register(DrawerlessWoodIngredient.NAME, DrawerlessWoodIngredient.SERIALIZER); }).subscribe(); + EventManager.modGeneric(RegistryEvent.Register.class, RecipeSerializer.class) + .process(register -> ((RegistryEvent.Register) register).getRegistry() + .registerAll(FramedDrawerRecipe.SERIALIZER.setRegistryName(new ResourceLocation(MOD_ID, "framed_recipe")))).subscribe(); + NBTManager.getInstance().scanTileClassForAnnotations(FramedDrawerTile.class); } @@ -147,8 +153,13 @@ public class FunctionalStorage extends ModuleController { for (DrawerType value : DrawerType.values()) { for (IWoodType woodType : WOOD_TYPES) { String name = woodType.getName() + "_" + value.getSlots(); - DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value), blockRegistryObject -> () -> - new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); + if (woodType == DrawerWoodType.FRAMED){ + DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new FramedDrawerBlock(value), blockRegistryObject -> () -> + new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); + } else { + DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value), blockRegistryObject -> () -> + new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); + } } DRAWER_TYPES.get(value).forEach(blockRegistryObject -> TAB.addIconStacks(() -> new ItemStack(blockRegistryObject.getLeft().get()))); } @@ -260,6 +271,9 @@ public class FunctionalStorage extends ModuleController { } }); }).subscribe(); + EventManager.mod(ModelRegistryEvent.class).process(modelRegistryEvent -> { + ModelLoaderRegistry.registerLoader(new ResourceLocation(MOD_ID, "framed"), RetexturedModel.Loader.INSTANCE); + }).subscribe(); } @Override diff --git a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java index 3811cf5..996b7ae 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java @@ -2,10 +2,39 @@ package com.buuz135.functionalstorage.block; import com.buuz135.functionalstorage.FunctionalStorage; 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.inventory.item.DrawerCapabilityProvider; +import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; import com.buuz135.functionalstorage.util.DrawerWoodType; import com.buuz135.functionalstorage.util.IWoodType; +import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; +import com.hrznstudio.titanium.util.ItemHandlerUtil; +import com.hrznstudio.titanium.util.TileUtil; +import net.minecraft.core.BlockPos; +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.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +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.minecraftforge.common.Tags; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +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.Optional; +import java.util.function.Consumer; public class FramedDrawerBlock extends DrawerBlock{ @@ -15,6 +44,63 @@ public class FramedDrawerBlock extends DrawerBlock{ @Override public BlockEntityType.BlockEntitySupplier getTileEntityFactory() { - return (blockPos, state) -> new DrawerTile(this, (BlockEntityType) FunctionalStorage.DRAWER_TYPES.get(this.getType()).stream().filter(registryObjectRegistryObjectPair -> registryObjectRegistryObjectPair.getLeft().get().equals(this)).map(Pair::getRight).findFirst().get().get(), blockPos, state, this.getType()); + return (blockPos, state) -> new FramedDrawerTile(this, (BlockEntityType) FunctionalStorage.DRAWER_TYPES.get(this.getType()).stream().filter(registryObjectRegistryObjectPair -> registryObjectRegistryObjectPair.getLeft().get().equals(this)).map(Pair::getRight).findFirst().get().get(), blockPos, state, this.getType()); + } + + @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, FramedDrawerTile.class).ifPresent(framedDrawerTile -> { + framedDrawerTile.setFramedDrawerModelData(getDrawerModelData(stack)); + }); + } + + public static FramedDrawerModelData getDrawerModelData(ItemStack stack){ + if (stack.hasTag() && stack.getTag().contains("Style")){ + CompoundTag tag = stack.getTag().getCompound("Style"); + HashMap data = new HashMap<>(); + data.put("particle", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("particle")))); + data.put("front", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("front")))); + data.put("side", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("side")))); + return new FramedDrawerModelData(data); + } + return null; + } + + public static ItemStack fill(ItemStack first, ItemStack second, ItemStack drawer){ + drawer = ItemHandlerHelper.copyStackWithSize(drawer, 1); + CompoundTag style = drawer.getOrCreateTagElement("Style"); + style.putString("particle", first.getItem().getRegistryName().toString()); + style.putString("side", first.getItem().getRegistryName().toString()); + style.putString("front", second.getItem().getRegistryName().toString()); + drawer.getOrCreateTag().put("Style", style); + return drawer; + } + + @Override + public void registerRecipe(Consumer consumer) { + if (this.getType() == FunctionalStorage.DrawerType.X_1) { + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .pattern("PPP").pattern("PCP").pattern("PPP") + .define('P', Items.IRON_NUGGET) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + } + if (this.getType() == FunctionalStorage.DrawerType.X_2){ + TitaniumShapedRecipeBuilder.shapedRecipe(this, 2) + .pattern("PCP").pattern("PPP").pattern("PCP") + .define('P', Items.IRON_NUGGET) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + + } + if (this.getType() == FunctionalStorage.DrawerType.X_4){ + TitaniumShapedRecipeBuilder.shapedRecipe(this, 4) + .pattern("CPC").pattern("PPP").pattern("CPC") + .define('P', Items.IRON_NUGGET) + .define('C', Tags.Items.CHESTS_WOODEN) + .save(consumer); + + } } } diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java index 93ec3d6..e6ecd12 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/FramedDrawerTile.java @@ -1,14 +1,41 @@ 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.Level; 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 FramedDrawerTile extends DrawerTile{ + @Save + private FramedDrawerModelData framedDrawerModelData; public FramedDrawerTile(BasicTileBlock base, BlockEntityType blockEntityType, BlockPos pos, BlockState state, FunctionalStorage.DrawerType type) { super(base, blockEntityType, pos, state, type); + 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(); } } diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/DynamicBakedWrapper.java b/src/main/java/com/buuz135/functionalstorage/client/loader/DynamicBakedWrapper.java new file mode 100644 index 0000000..e3a6004 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/DynamicBakedWrapper.java @@ -0,0 +1,40 @@ +package com.buuz135.functionalstorage.client.loader; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.BakedModelWrapper; +import net.minecraftforge.client.model.data.EmptyModelData; +import net.minecraftforge.client.model.data.IModelData; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Random; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + * + * Cross between {@link BakedModelWrapper} and {@link net.minecraftforge.client.model.data.IDynamicBakedModel}. + * Used to create a baked model wrapper that has a dynamic {@link #getQuads(BlockState, Direction, Random, IModelData)} without worrying about overriding the deprecated variant. + * @param Baked model parent + */ +@SuppressWarnings("WeakerAccess") +public abstract class DynamicBakedWrapper extends BakedModelWrapper { + + protected DynamicBakedWrapper(T originalModel) { + super(originalModel); + } + + /** + * @deprecated use {@link #getQuads(BlockState, Direction, Random, IModelData)} + */ + @Override + @Deprecated + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { + return this.getQuads(state, side, rand, EmptyModelData.INSTANCE); + } + + @Override + public abstract List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData); +} diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/ModelConfigurationWrapper.java b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelConfigurationWrapper.java new file mode 100644 index 0000000..0f1c971 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelConfigurationWrapper.java @@ -0,0 +1,79 @@ +package com.buuz135.functionalstorage.client.loader; + +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.resources.model.Material; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometryPart; + +import javax.annotation.Nullable; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + * + * Wrapper around a {@link IModelConfiguration} instance to allow easier extending, mostly for dynamic textures + */ +@SuppressWarnings("WeakerAccess") +public class ModelConfigurationWrapper implements IModelConfiguration { + private final IModelConfiguration base; + + /** + * Creates a new configuration wrapper + * @param base Base model configuration + */ + public ModelConfigurationWrapper(IModelConfiguration base) { + this.base = base; + } + + @Nullable + @Override + public UnbakedModel getOwnerModel() { + return base.getOwnerModel(); + } + + @Override + public String getModelName() { + return base.getModelName(); + } + + @Override + public boolean isTexturePresent(String name) { + return base.isTexturePresent(name); + } + + @Override + public Material resolveTexture(String name) { + return base.resolveTexture(name); + } + + @Override + public boolean isShadedInGui() { + return base.isShadedInGui(); + } + + @Override + public boolean isSideLit() { + return base.isSideLit(); + } + + @Override + public boolean useSmoothLighting() { + return base.useSmoothLighting(); + } + + @Override + public ItemTransforms getCameraTransforms() { + return base.getCameraTransforms(); + } + + @Override + public ModelState getCombinedTransform() { + return base.getCombinedTransform(); + } + + @Override + public boolean getPartVisibility(IModelGeometryPart part, boolean fallback) { + return base.getPartVisibility(part, fallback); + } +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/ModelHelper.java b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelHelper.java new file mode 100644 index 0000000..c0fb09a --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelHelper.java @@ -0,0 +1,210 @@ +package com.buuz135.functionalstorage.client.loader; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.mojang.blaze3d.vertex.VertexFormatElement; +import com.mojang.math.Vector3f; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.MultiPartBakedModel; +import net.minecraft.client.resources.model.WeightedBakedModel; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManagerReloadListener; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; +import net.minecraftforge.client.model.pipeline.VertexTransformer; + +import javax.annotation.Nullable; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + * + * Utilities to help in custom models + */ + +public class ModelHelper { + private static final Map TEXTURE_NAME_CACHE = new ConcurrentHashMap<>(); + /** Listener instance to clear cache */ + public static final ResourceManagerReloadListener LISTENER = manager -> TEXTURE_NAME_CACHE.clear(); + + /* Baked models */ + + /** + * Gets the model for the given block + * @param state Block state + * @param clazz Class type to cast result into + * @param Class type + * @return Block model, or null if its missing or the wrong class type + */ + @Nullable + public static T getBakedModel(BlockState state, Class clazz) { + Minecraft minecraft = Minecraft.getInstance(); + //noinspection ConstantConditions null during run data + if (minecraft == null) { + return null; + } + BakedModel baked = minecraft.getModelManager().getBlockModelShaper().getBlockModel(state); + // map multipart and weighted random into the first variant + if (baked instanceof MultiPartBakedModel) { + baked = ((MultiPartBakedModel)baked).selectors.get(0).getRight(); + } + if (baked instanceof WeightedBakedModel) { + baked = ((WeightedBakedModel) baked).wrapped; + } + // final model should match the desired type + if (clazz.isInstance(baked)) { + return clazz.cast(baked); + } + return null; + } + + /** + * Gets the model for the given item + * @param item Item provider + * @param clazz Class type to cast result into + * @param Class type + * @return Item model, or null if its missing or the wrong class type + */ + @Nullable + public static T getBakedModel(ItemLike item, Class clazz) { + Minecraft minecraft = Minecraft.getInstance(); + //noinspection ConstantConditions null during run data + if (minecraft == null) { + return null; + } + BakedModel baked = minecraft.getItemRenderer().getItemModelShaper().getItemModel(item.asItem()); + if (clazz.isInstance(baked)) { + return clazz.cast(baked); + } + return null; + } + + /** + * Gets the texture name for a block from the model manager + * @param block Block to fetch + * @return Texture name for the block + */ + @SuppressWarnings("deprecation") + private static ResourceLocation getParticleTextureInternal(Block block) { + return Minecraft.getInstance().getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getParticleIcon().getName(); + } + + /** + * Gets the name of a particle texture for a block, using the cached value if present + * @param block Block to fetch + * @return Texture name for the block + */ + public static ResourceLocation getParticleTexture(Block block) { + return TEXTURE_NAME_CACHE.computeIfAbsent(block, ModelHelper::getParticleTextureInternal); + } + + public static ResourceLocation getParticleTexture(Item block) { + return TEXTURE_NAME_CACHE.computeIfAbsent(Block.byItem(block), ModelHelper::getParticleTextureInternal); + } + + /* JSON */ + + /** + * Converts a JSON float array to the specified object + * @param json JSON object + * @param name Name of the array in the object to fetch + * @param size Expected array size + * @param mapper Functon to map from the array to the output type + * @param Output type + * @return Vector3f of data + * @throws JsonParseException If there is no array or the length is wrong + */ + public static T arrayToObject(JsonObject json, String name, int size, Function mapper) { + JsonArray array = GsonHelper.getAsJsonArray(json, name); + if (array.size() != size) { + throw new JsonParseException("Expected " + size + " " + name + " values, found: " + array.size()); + } + float[] vec = new float[size]; + for(int i = 0; i < size; ++i) { + vec[i] = GsonHelper.convertToFloat(array.get(i), name + "[" + i + "]"); + } + return mapper.apply(vec); + } + + /** + * Converts a JSON array with 3 elements into a Vector3f + * @param json JSON object + * @param name Name of the array in the object to fetch + * @return Vector3f of data + * @throws JsonParseException If there is no array or the length is wrong + */ + public static Vector3f arrayToVector(JsonObject json, String name) { + return arrayToObject(json, name, 3, arr -> new Vector3f(arr[0], arr[1], arr[2])); + } + + /** + * Gets a rotation from JSON + * @param json JSON parent + * @return Integer of 0, 90, 180, or 270 + */ + public static int getRotation(JsonObject json, String key) { + int i = GsonHelper.getAsInt(json, key, 0); + if (i >= 0 && i % 90 == 0 && i / 90 <= 3) { + return i; + } else { + throw new JsonParseException("Invalid '" + key + "' " + i + " found, only 0/90/180/270 allowed"); + } + } + + public static BakedQuad colorQuad(int color, BakedQuad quad) { + ColorTransformer transformer = new ColorTransformer(color, quad); + quad.pipe(transformer); + return transformer.build(); + } + + + private static class ColorTransformer extends VertexTransformer { + + private final float r, g, b, a; + + public ColorTransformer(int color, BakedQuad quad) { + super(new BakedQuadBuilder(quad.getSprite())); + + int a = (color >> 24); + if (a == 0) { + a = 255; + } + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = (color >> 0) & 0xFF; + + this.r = (float) r / 255f; + this.g = (float) g / 255f; + this.b = (float) b / 255f; + this.a = (float) a / 255f; + } + + @Override + public void put(int element, float... data) { + VertexFormatElement.Usage usage = this.parent.getVertexFormat().getElements().get(element).getUsage(); + + // transform normals and position + if (usage == VertexFormatElement.Usage.COLOR && data.length >= 4) { + data[0] = this.r; + data[1] = this.g; + data[2] = this.b; + data[3] = this.a; + } + super.put(element, data); + } + + public BakedQuad build() { + return ((BakedQuadBuilder) this.parent).build(); + } + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/ModelTextureIteratable.java b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelTextureIteratable.java new file mode 100644 index 0000000..84a083b --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/ModelTextureIteratable.java @@ -0,0 +1,91 @@ +package com.buuz135.functionalstorage.client.loader; + +import com.mojang.datafixers.util.Either; +import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.Material; +import net.minecraftforge.client.model.IModelConfiguration; + +import javax.annotation.Nullable; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + */ +public class ModelTextureIteratable implements Iterable>> { + /** Initial map for iteration */ + @Nullable + private final Map> startMap; + /** Initial model for iteration */ + @Nullable + private final BlockModel startModel; + + public ModelTextureIteratable(@Nullable Map> startMap, @Nullable BlockModel startModel) { + this.startMap = startMap; + this.startModel = startModel; + } + + /** + * Creates an iterable over the given model + * @param model Model + */ + public ModelTextureIteratable(BlockModel model) { + this(null, model); + } + + /** + * + * @param owner Model configuration owner + * @param fallback Fallback in case the owner does not contain a block model + * @return Iteratable over block model texture maps + */ + public static ModelTextureIteratable of(IModelConfiguration owner, SimpleBlockModel fallback) { + UnbakedModel unbaked = owner.getOwnerModel(); + if (unbaked instanceof BlockModel) { + return new ModelTextureIteratable(null, (BlockModel)unbaked); + } + return new ModelTextureIteratable(fallback.getTextures(), fallback.getParent()); + } + + @Override + public MapIterator iterator() { + return new MapIterator(startMap, startModel); + } + + private static class MapIterator implements Iterator>> { + + public MapIterator(@Nullable Map> initial, @Nullable BlockModel model) { + this.initial = initial; + this.model = model; + } + + /** Initial map for iteration */ + @Nullable + private Map> initial; + /** current model in the iterator */ + @Nullable + private BlockModel model; + + @Override + public boolean hasNext() { + return initial != null || model != null; + } + + @Override + public Map> next() { + Map> map; + if (initial != null) { + map = initial; + initial = null; + } else if (model != null) { + map = model.textureMap; + model = model.parent; + } else { + throw new NoSuchElementException(); + } + return map; + } + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedHelper.java b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedHelper.java new file mode 100644 index 0000000..12c300e --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedHelper.java @@ -0,0 +1,70 @@ +package com.buuz135.functionalstorage.client.loader; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraftforge.client.model.data.ModelProperty; +import net.minecraftforge.registries.ForgeRegistries; + +import javax.annotation.Nullable; + +/** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + * + * This utility contains helpers to handle the NBT for retexturable blocks + */ + +public final class RetexturedHelper { + /** Tag name for texture blocks. Should not be used directly, use the utils to interact */ + private static final String TAG_TEXTURE = "texture"; + /** Property for tile entities containing a texture block */ + + + /* Getting */ + + /** + * Gets a block for the given name + * @param name Block name + * @return Block entry, or {@link Blocks#AIR} if no match + */ + public static Block getBlock(String name) { + if (!name.isEmpty()) { + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name)); + if (block != null) { + return block; + } + } + return Blocks.AIR; + } + + /** + * Gets the name of the texture from NBT + * @param nbt NBT tag + * @return Name of the texture, or empty if no texture + */ + public static String getTextureName(@Nullable CompoundTag nbt) { + if (nbt == null) { + return ""; + } + return nbt.getString(TAG_TEXTURE); + } + + + /* Setting */ + + /** + * Sets the texture in an NBT instance + * @param nbt Tag instance + * @param texture Texture to set + */ + public static void setTexture(@Nullable CompoundTag nbt, String texture) { + if (nbt != null) { + if (texture.isEmpty()) { + nbt.remove(TAG_TEXTURE); + } else { + nbt.putString(TAG_TEXTURE, texture); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java index 99b73f3..280727d 100644 --- a/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/RetexturedModel.java @@ -1,5 +1,7 @@ package com.buuz135.functionalstorage.client.loader; +import com.buuz135.functionalstorage.block.FramedDrawerBlock; +import com.buuz135.functionalstorage.client.model.FramedDrawerModelData; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.gson.JsonArray; @@ -25,8 +27,6 @@ import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.util.GsonHelper; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.model.IModelConfiguration; import net.minecraftforge.client.model.IModelLoader; @@ -37,11 +37,7 @@ import net.minecraftforge.client.model.geometry.IModelGeometry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -56,6 +52,11 @@ public class RetexturedModel implements IModelGeometry { private final SimpleBlockModel model; private final Set retextured; + public RetexturedModel(SimpleBlockModel model, Set retextured) { + this.model = model; + this.retextured = retextured; + } + @Override public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { return model.getTextures(owner, modelGetter, missingTextureErrors); @@ -143,7 +144,7 @@ public class RetexturedModel implements IModelGeometry { /** Baked variant of the model, used to swap out quads based on the texture */ public static class Baked extends DynamicBakedWrapper { /** Cache of texture name to baked model */ - private final Map cache = new ConcurrentHashMap<>(); + private final Map cache = new ConcurrentHashMap<>(); /* Properties for rebaking */ private final IModelConfiguration owner; private final SimpleBlockModel model; @@ -161,29 +162,29 @@ public class RetexturedModel implements IModelGeometry { /** * Gets the model with the given texture applied - * @param name Texture location + * @param framedDrawerModelData Texture location * @return Retextured model */ - private BakedModel getRetexturedModel(ResourceLocation name) { - return model.bakeDynamic(new RetexturedConfiguration(owner, retextured, name), transform); + private BakedModel getRetexturedModel(FramedDrawerModelData framedDrawerModelData) { + return model.bakeDynamic(new RetexturedConfiguration(owner, retextured, framedDrawerModelData), transform); } /** * Gets a cached retextured model, computing it if missing from the cache - * @param block Block determining the texture + * @param framedDrawerModelData Block determining the texture * @return Retextured model */ - private BakedModel getCachedModel(Block block) { - return cache.computeIfAbsent(ModelHelper.getParticleTexture(block), this::getRetexturedModel); + private BakedModel getCachedModel(FramedDrawerModelData framedDrawerModelData) { + return cache.computeIfAbsent(framedDrawerModelData.getCode(), (s) -> this.getRetexturedModel(framedDrawerModelData)); } @Override public TextureAtlasSprite getParticleIcon(IModelData data) { // if particle is retextured, fetch particle from the cached model if (retextured.contains("particle")) { - Block block = data.getData(RetexturedHelper.BLOCK_PROPERTY); - if (block != null) { - return getCachedModel(block).getParticleIcon(data); + FramedDrawerModelData framedDrawerModelData = data.getData(FramedDrawerModelData.FRAMED_PROPERTY); + if (framedDrawerModelData != null) { + return getCachedModel(framedDrawerModelData).getParticleIcon(data); } } return originalModel.getParticleIcon(data); @@ -192,11 +193,11 @@ public class RetexturedModel implements IModelGeometry { @Nonnull @Override public List getQuads(@Nullable BlockState state, @Nullable Direction direction, Random random, IModelData data) { - Block block = data.getData(RetexturedHelper.BLOCK_PROPERTY); - if (block == null) { + FramedDrawerModelData framedDrawerModelData = data.getData(FramedDrawerModelData.FRAMED_PROPERTY); + if (framedDrawerModelData == null) { return originalModel.getQuads(state, direction, random, data); } - return getCachedModel(block).getQuads(state, direction, random, data); + return getCachedModel(framedDrawerModelData).getQuads(state, direction, random, data); } @Override @@ -212,7 +213,7 @@ public class RetexturedModel implements IModelGeometry { /** List of textures to retexture */ private final Set retextured; /** Replacement texture */ - private final Material texture; + private final HashMap texture; /** * Creates a new configuration wrapper @@ -220,24 +221,27 @@ public class RetexturedModel implements IModelGeometry { * @param retextured Set of textures that should be retextured * @param texture New texture to replace those in the set */ - public RetexturedConfiguration(IModelConfiguration base, Set retextured, ResourceLocation texture) { + public RetexturedConfiguration(IModelConfiguration base, Set retextured, FramedDrawerModelData texture) { super(base); this.retextured = retextured; - this.texture = ModelLoaderRegistry.blockMaterial(texture); + this.texture = new HashMap<>(); + texture.getDesign().forEach((s, item) -> { + this.texture.put(s, ModelLoaderRegistry.blockMaterial(ModelHelper.getParticleTexture(item))); + }); } @Override public boolean isTexturePresent(String name) { - if (retextured.contains(name)) { - return !MissingTextureAtlasSprite.getLocation().equals(texture.texture()); + if (retextured.contains(name) && texture.containsKey(name)) { + return !MissingTextureAtlasSprite.getLocation().equals(texture.get(name).texture()); } return super.isTexturePresent(name); } @Override public Material resolveTexture(String name) { - if (retextured.contains(name)) { - return texture; + if (retextured.contains(name) && texture.containsKey(name)) { + return texture.get(name); } return super.resolveTexture(name); } @@ -255,13 +259,13 @@ public class RetexturedModel implements IModelGeometry { } // get the block first, ensuring its valid - Block block = RetexturedBlockItem.getTexture(stack); - if (block == Blocks.AIR) { + FramedDrawerModelData data = FramedDrawerBlock.getDrawerModelData(stack); + if (data == null) { return originalModel; } // if valid, use the block - return ((Baked)originalModel).getCachedModel(block); + return ((Baked)originalModel).getCachedModel(data); } } } diff --git a/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java b/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java index 99777bc..a411435 100644 --- a/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java +++ b/src/main/java/com/buuz135/functionalstorage/client/loader/SimpleBlockModel.java @@ -47,6 +47,8 @@ import java.util.function.Function; import java.util.stream.Collectors; /** + * Class from Mantle {@url https://github.com/SlimeKnights/Mantle/blob/1.18.2/src/main/java/slimeknights/mantle/client/} + * * Simplier version of {@link BlockModel} for use in an {@link net.minecraftforge.client.model.IModelLoader}, as the owner handles most block model properties */ @SuppressWarnings("WeakerAccess") @@ -247,7 +249,7 @@ public class SimpleBlockModel implements IModelGeometry { } // bake the face TextureAtlasSprite sprite = spriteGetter.apply(owner.resolveTexture(texture)); - BakedQuad bakedQuad = BlockModel.makeBakedQuad(part, face, sprite, direction, transform, location); + BakedQuad bakedQuad = BlockModel.bakeFace(part, face, sprite, direction, transform, location); // apply cull face if (face.cullForDirection == null) { builder.addUnculledFace(bakedQuad); diff --git a/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java index 876309a..03ee38f 100644 --- a/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java +++ b/src/main/java/com/buuz135/functionalstorage/client/model/FramedDrawerModelData.java @@ -23,22 +23,56 @@ package com.buuz135.functionalstorage.client.model; -import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraftforge.client.model.data.ModelProperty; +import net.minecraftforge.common.util.INBTSerializable; +import net.minecraftforge.registries.ForgeRegistries; +import java.util.HashMap; import java.util.Map; -public class FramedDrawerModelData { +public class FramedDrawerModelData implements INBTSerializable { - public static final ModelProperty UPGRADE_PROPERTY = new ModelProperty<>(); - private Map design; + public static final ModelProperty FRAMED_PROPERTY = new ModelProperty<>(); + private Map design; - public FramedDrawerModelData(Map design) { + private String code = ""; + + public FramedDrawerModelData(Map design) { this.design = design; + this.generateCode(); } - public Map getDesign() { + public Map getDesign() { return design; } + + @Override + public CompoundTag serializeNBT() { + CompoundTag compoundTag = new CompoundTag(); + design.forEach((s, item) -> compoundTag.putString(s, item.getRegistryName().toString())); + return compoundTag; + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + design = new HashMap<>(); + for (String allKey : nbt.getAllKeys()) { + design.put(allKey, ForgeRegistries.ITEMS.getValue(new ResourceLocation(nbt.getString(allKey)))); + } + this.generateCode(); + } + + private void generateCode(){ + this.code = ""; + this.design.forEach((s, item) -> { + this.code += (s + item.getRegistryName().toString()); + }); + } + + public String getCode() { + return code; + } } diff --git a/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java b/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java new file mode 100644 index 0000000..b14e0eb --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java @@ -0,0 +1,53 @@ +package com.buuz135.functionalstorage.recipe; + + +import com.buuz135.functionalstorage.block.FramedDrawerBlock; +import com.google.common.collect.Lists; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CustomRecipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.SimpleRecipeSerializer; +import net.minecraft.world.level.Level; + +import java.util.List; + +public class FramedDrawerRecipe extends CustomRecipe { + + public static RecipeSerializer SERIALIZER = new SimpleRecipeSerializer<>(FramedDrawerRecipe::new); + + public FramedDrawerRecipe(ResourceLocation idIn) { + super(idIn); + } + + + public static boolean matches(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 FramedDrawerBlock; + } + + @Override + public boolean matches(CraftingContainer inv, Level worldIn) { + return matches(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))){ + return FramedDrawerBlock.fill(inv.getItem(0), inv.getItem(1), inv.getItem(2).copy()); + } + return ItemStack.EMPTY; + } + + @Override + public boolean canCraftInDimensions(int width, int height) { + return width * height >= 2; + } + + @Override + public RecipeSerializer getSerializer() { + return SERIALIZER; + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/util/DrawerWoodType.java b/src/main/java/com/buuz135/functionalstorage/util/DrawerWoodType.java index fc46631..891cec6 100644 --- a/src/main/java/com/buuz135/functionalstorage/util/DrawerWoodType.java +++ b/src/main/java/com/buuz135/functionalstorage/util/DrawerWoodType.java @@ -14,7 +14,8 @@ public enum DrawerWoodType implements IWoodType { ACACIA(Blocks.ACACIA_LOG, Blocks.ACACIA_PLANKS), DARK_OAK(Blocks.DARK_OAK_LOG, Blocks.DARK_OAK_PLANKS), CRIMSON(Blocks.CRIMSON_STEM, Blocks.CRIMSON_PLANKS), - WARPED(Blocks.WARPED_STEM, Blocks.WARPED_PLANKS); + WARPED(Blocks.WARPED_STEM, Blocks.WARPED_PLANKS), + FRAMED(Blocks.STONE, Blocks.STONE); private final Block log; diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 74631bb..aac003a 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1 +1,7 @@ -public net.minecraft.client.renderer.RenderStateShard$LineStateShard \ No newline at end of file +public net.minecraft.client.renderer.RenderStateShard$LineStateShard +public net.minecraft.client.renderer.block.model.BlockModel f_111419_ # parentLocation +public net.minecraft.client.renderer.block.model.BlockModel m_111437_(Lnet/minecraft/client/renderer/block/model/BlockElement;Lnet/minecraft/client/renderer/block/model/BlockElementFace;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/minecraft/core/Direction;Lnet/minecraft/client/resources/model/ModelState;Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BakedQuad; # bakeFace +public net.minecraft.client.renderer.block.model.BlockModel$Deserializer m_111503_(Lnet/minecraft/resources/ResourceLocation;Ljava/lang/String;)Lcom/mojang/datafixers/util/Either; # findTexture + +public net.minecraft.client.resources.model.WeightedBakedModel f_119542_ # baseModel +public net.minecraft.client.resources.model.MultiPartBakedModel f_119459_ # selectors \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json b/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json similarity index 79% rename from src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json rename to src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json index ac9f872..24c380e 100644 --- a/src/main/resources/assets/functionalstorage/models/block/base_framing_x_1_sides.json +++ b/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json @@ -15,16 +15,32 @@ } }, { - "from": [0, 15, 0], - "to": [16, 16, 16], + "from": [1, 9, 0.5], + "to": [15, 15, 2.5], "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, "faces": { - "north": {"uv": [0, 0, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, - "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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"} + "north": {"uv": [1, 1, 15, 7], "texture": "#front"}, + "down": {"uv": [0, 0, 6, 2], "texture": "#side"} + } + }, + { + "name": "divider", + "from": [1, 7, 0], + "to": [15, 9, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 7, 15, 9], "texture": "#side", "cullface": "north"}, + "up": {"uv": [15, 7, 1, 9], "texture": "#side"}, + "down": {"uv": [1, 9, 15, 7], "rotation": 180, "texture": "#side"} + } + }, + { + "from": [1, 1, 0.5], + "to": [15, 7, 2.5], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 9, 15, 15], "texture": "#front"}, + "up": {"uv": [0, 0, 6, 2], "texture": "#side"} } }, { @@ -50,6 +66,19 @@ "down": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "down"} } }, + { + "from": [0, 15, 0], + "to": [16, 16, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [0, 0, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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, 15], "to": [16, 15, 16], diff --git a/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json b/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json new file mode 100644 index 0000000..3bad769 --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json @@ -0,0 +1,175 @@ +{ + "credit": "Made with Blockbench", + "textures": { + "lock_icon": "functionalstorage:blocks/unlock" + }, + "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": [7, 15, 2.5], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [9, 1, 15, 7], "texture": "#front"}, + "east": {"uv": [0, 0, 2, 6], "texture": "#front"}, + "down": {"uv": [0, 0, 6, 2], "texture": "#front"} + } + }, + { + "from": [9, 9, 0.5], + "to": [15, 15, 2.5], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 1, 7, 7], "texture": "#front"}, + "west": {"uv": [0, 0, 2, 6], "texture": "#front"}, + "down": {"uv": [0, 0, 6, 2], "texture": "#front"} + } + }, + { + "name": "divider", + "from": [7, 1, 0], + "to": [9, 15, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [7, 1, 9, 15], "texture": "#side", "cullface": "north"}, + "east": {"uv": [9, 1, 7, 15], "texture": "#side"}, + "west": {"uv": [9, 1, 7, 15], "texture": "#side"} + } + }, + { + "name": "divider", + "from": [9, 7, 0], + "to": [15, 9, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 7, 7, 9], "texture": "#side", "cullface": "north"}, + "up": {"uv": [7, 7, 1, 9], "texture": "#side"}, + "down": {"uv": [7, 7, 1, 9], "texture": "#side"} + } + }, + { + "name": "divider", + "from": [1, 7, 0], + "to": [7, 9, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [9, 7, 15, 9], "texture": "#side", "cullface": "north"}, + "up": {"uv": [15, 7, 9, 9], "texture": "#side"}, + "down": {"uv": [15, 7, 9, 9], "texture": "#side"} + } + }, + { + "from": [0, 0, 0], + "to": [16, 1, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [0, 0, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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"}, + "down": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "down"} + } + }, + { + "from": [0, 1, 0], + "to": [1, 15, 15], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 15, 15, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [1, 1, 16, 15], "texture": "#side"}, + "west": {"uv": [0, 1, 15, 15], "texture": "#side", "cullface": "west"} + } + }, + { + "from": [0, 15, 0], + "to": [16, 16, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [0, 0, 1, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [0, 0, 16, 1], "rotation": 180, "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": [15, 1, 0], + "to": [16, 15, 15], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "north": {"uv": [1, 15, 15, 16], "rotation": 90, "texture": "#side", "cullface": "north"}, + "east": {"uv": [1, 1, 16, 15], "texture": "#side", "cullface": "east"}, + "west": {"uv": [0, 1, 15, 15], "texture": "#side"} + } + }, + { + "from": [0, 1, 15], + "to": [16, 15, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, + "faces": { + "east": {"uv": [1, 0, 15, 1], "rotation": 90, "texture": "#side", "cullface": "east"}, + "south": {"uv": [0, 1, 16, 15], "texture": "#side", "cullface": "south"}, + "west": {"uv": [1, 15, 15, 16], "rotation": 90, "texture": "#side", "cullface": "west"} + } + }, + { + "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, 45, 0], + "scale": [0.4, 0.4, 0.4] + }, + "firstperson_lefthand": { + "rotation": [0, 225, 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] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_1.json b/src/main/resources/assets/functionalstorage/models/block/framed_1.json index 3452687..134dcc0 100644 --- a/src/main/resources/assets/functionalstorage/models/block/framed_1.json +++ b/src/main/resources/assets/functionalstorage/models/block/framed_1.json @@ -2,9 +2,7 @@ "loader": "functionalstorage:framed", "parent": "functionalstorage:block/base_x_1", "textures": { - "particle": "functionalstorage:blocks/acacia_front_1", - "front": "functionalstorage:blocks/acacia_front_1", - "side": "functionalstorage:blocks/acacia_side" + }, - "retextured": [ "particle", "side" ] + "retextured": [ "particle", "side", "front" ] } \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_2.json b/src/main/resources/assets/functionalstorage/models/block/framed_2.json new file mode 100644 index 0000000..3db38e0 --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/framed_2.json @@ -0,0 +1,8 @@ +{ + "loader": "functionalstorage:framed", + "parent": "functionalstorage:block/base_x_2_framed", + "textures": { + + }, + "retextured": [ "particle", "side", "front" ] +} \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_4.json b/src/main/resources/assets/functionalstorage/models/block/framed_4.json new file mode 100644 index 0000000..9e2e63b --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/framed_4.json @@ -0,0 +1,8 @@ +{ + "loader": "functionalstorage:framed", + "parent": "functionalstorage:block/base_x_4_framed", + "textures": { + + }, + "retextured": [ "particle", "side", "front" ] +} \ No newline at end of file diff --git a/src/main/resources/data/functionalstorage/recipes/framed.json b/src/main/resources/data/functionalstorage/recipes/framed.json new file mode 100644 index 0000000..d05b81a --- /dev/null +++ b/src/main/resources/data/functionalstorage/recipes/framed.json @@ -0,0 +1,3 @@ +{ + "type": "functionalstorage:framed_recipe" +} \ No newline at end of file From c77dae246755687296e5e8d0b80b008bcf999a86 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 3 Jul 2022 20:33:52 +0200 Subject: [PATCH 3/7] Fixed Drawer drops and added some missing data --- .../loot_tables/blocks/framed_1.json | 3 ++ .../loot_tables/blocks/framed_2.json | 3 ++ .../loot_tables/blocks/framed_4.json | 3 ++ .../functionalstorage/recipes/framed_1.json | 37 ++++++++++++++++++ .../functionalstorage/recipes/framed_2.json | 38 +++++++++++++++++++ .../functionalstorage/recipes/framed_4.json | 38 +++++++++++++++++++ .../minecraft/tags/blocks/mineable/axe.json | 35 +++++++++-------- .../block/FramedDrawerBlock.java | 33 ++++++++++++++++ 8 files changed, 174 insertions(+), 16 deletions(-) create mode 100644 src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_1.json create mode 100644 src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_2.json create mode 100644 src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_4.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/framed_1.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/framed_2.json create mode 100644 src/generated/resources/data/functionalstorage/recipes/framed_4.json diff --git a/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_1.json b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_1.json new file mode 100644 index 0000000..68701f9 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_1.json @@ -0,0 +1,3 @@ +{ + "type": "minecraft:block" +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_2.json b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_2.json new file mode 100644 index 0000000..68701f9 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_2.json @@ -0,0 +1,3 @@ +{ + "type": "minecraft:block" +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_4.json b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_4.json new file mode 100644 index 0000000..68701f9 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/loot_tables/blocks/framed_4.json @@ -0,0 +1,3 @@ +{ + "type": "minecraft:block" +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/framed_1.json b/src/generated/resources/data/functionalstorage/recipes/framed_1.json new file mode 100644 index 0000000..de3af52 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/framed_1.json @@ -0,0 +1,37 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:framed_1", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "PPP", + "PCP", + "PPP" + ], + "key": { + "P": { + "item": "minecraft:iron_nugget" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:framed_1" + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/framed_2.json b/src/generated/resources/data/functionalstorage/recipes/framed_2.json new file mode 100644 index 0000000..e8487a2 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/framed_2.json @@ -0,0 +1,38 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:framed_2", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "PCP", + "PPP", + "PCP" + ], + "key": { + "P": { + "item": "minecraft:iron_nugget" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:framed_2", + "count": 2 + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/framed_4.json b/src/generated/resources/data/functionalstorage/recipes/framed_4.json new file mode 100644 index 0000000..96b46f4 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/framed_4.json @@ -0,0 +1,38 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:framed_4", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "CPC", + "PPP", + "CPC" + ], + "key": { + "P": { + "item": "minecraft:iron_nugget" + }, + "C": { + "tag": "forge:chests/wooden" + } + }, + "result": { + "item": "functionalstorage:framed_4", + "count": 4 + } + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json index 6dff867..9e05415 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json @@ -1,14 +1,15 @@ { "replace": false, "values": [ - "functionalstorage:oak_1", - "functionalstorage:spruce_1", - "functionalstorage:birch_1", - "functionalstorage:jungle_1", - "functionalstorage:acacia_1", - "functionalstorage:dark_oak_1", - "functionalstorage:crimson_1", - "functionalstorage:warped_1", + "functionalstorage:oak_2", + "functionalstorage:spruce_2", + "functionalstorage:birch_2", + "functionalstorage:jungle_2", + "functionalstorage:acacia_2", + "functionalstorage:dark_oak_2", + "functionalstorage:crimson_2", + "functionalstorage:warped_2", + "functionalstorage:framed_2", "functionalstorage:oak_4", "functionalstorage:spruce_4", "functionalstorage:birch_4", @@ -17,13 +18,15 @@ "functionalstorage:dark_oak_4", "functionalstorage:crimson_4", "functionalstorage:warped_4", - "functionalstorage:oak_2", - "functionalstorage:spruce_2", - "functionalstorage:birch_2", - "functionalstorage:jungle_2", - "functionalstorage:acacia_2", - "functionalstorage:dark_oak_2", - "functionalstorage:crimson_2", - "functionalstorage:warped_2" + "functionalstorage:framed_4", + "functionalstorage:oak_1", + "functionalstorage:spruce_1", + "functionalstorage:birch_1", + "functionalstorage:jungle_1", + "functionalstorage:acacia_1", + "functionalstorage:dark_oak_1", + "functionalstorage:crimson_1", + "functionalstorage:warped_1", + "functionalstorage:framed_1" ] } \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java index 996b7ae..6d4a2ee 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java @@ -12,19 +12,25 @@ import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; import com.hrznstudio.titanium.util.ItemHandlerUtil; 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.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.BlockItem; 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.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.ItemHandlerHelper; @@ -33,6 +39,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.Nullable; import java.util.HashMap; +import java.util.List; import java.util.Optional; import java.util.function.Consumer; @@ -77,6 +84,32 @@ public class FramedDrawerBlock extends DrawerBlock{ return drawer; } + @Override + public List getDrops(BlockState p_60537_, LootContext.Builder builder) { + NonNullList stacks = NonNullList.create(); + ItemStack stack = new ItemStack(this); + BlockEntity drawerTile = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); + if (drawerTile instanceof FramedDrawerTile) { + if (!((FramedDrawerTile) drawerTile).isEverythingEmpty()) { + stack.getOrCreateTag().put("Tile", drawerTile.saveWithoutMetadata()); + } + stack.getOrCreateTag().put("Style", ((FramedDrawerTile) 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 FramedDrawerTile 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 consumer) { if (this.getType() == FunctionalStorage.DrawerType.X_1) { From 08d3805011867caf3a4780465357e732068e0751 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Fri, 8 Jul 2022 22:22:09 +0200 Subject: [PATCH 4/7] Compacted drawers --- .../blockstates/compacting_framed_drawer.json | 34 ++++ .../assets/functionalstorage/lang/en_us.json | 1 + .../compacting_framed_drawer_locked.json | 6 + .../models/item/compacting_framed_drawer.json | 3 + .../blocks/compacting_framed_drawer.json | 3 + .../tags/blocks/mineable/pickaxe.json | 1 + .../functionalstorage/FunctionalStorage.java | 5 + .../block/CompactingFramedDrawerBlock.java | 90 ++++++++++ .../functionalstorage/block/DrawerBlock.java | 2 +- .../tile/CompactingFramedDrawerTile.java | 40 +++++ .../recipe/FramedDrawerRecipe.java | 10 +- .../block/compacting_framed_drawer.json | 157 ++++++++++++++++++ 12 files changed, 349 insertions(+), 3 deletions(-) create mode 100644 src/generated/resources/assets/functionalstorage/blockstates/compacting_framed_drawer.json create mode 100644 src/generated/resources/assets/functionalstorage/models/block/compacting_framed_drawer_locked.json create mode 100644 src/generated/resources/assets/functionalstorage/models/item/compacting_framed_drawer.json create mode 100644 src/generated/resources/data/functionalstorage/loot_tables/blocks/compacting_framed_drawer.json create mode 100644 src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java create mode 100644 src/main/java/com/buuz135/functionalstorage/block/tile/CompactingFramedDrawerTile.java create mode 100644 src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json diff --git a/src/generated/resources/assets/functionalstorage/blockstates/compacting_framed_drawer.json b/src/generated/resources/assets/functionalstorage/blockstates/compacting_framed_drawer.json new file mode 100644 index 0000000..8212fa3 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/blockstates/compacting_framed_drawer.json @@ -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 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/lang/en_us.json b/src/generated/resources/assets/functionalstorage/lang/en_us.json index 7be8a66..17a78ac 100644 --- a/src/generated/resources/assets/functionalstorage/lang/en_us.json +++ b/src/generated/resources/assets/functionalstorage/lang/en_us.json @@ -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", diff --git a/src/generated/resources/assets/functionalstorage/models/block/compacting_framed_drawer_locked.json b/src/generated/resources/assets/functionalstorage/models/block/compacting_framed_drawer_locked.json new file mode 100644 index 0000000..df26b0b --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/block/compacting_framed_drawer_locked.json @@ -0,0 +1,6 @@ +{ + "parent": "functionalstorage:block/compacting_framed_drawer", + "textures": { + "lock_icon": "functionalstorage:blocks/lock" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/functionalstorage/models/item/compacting_framed_drawer.json b/src/generated/resources/assets/functionalstorage/models/item/compacting_framed_drawer.json new file mode 100644 index 0000000..e262581 --- /dev/null +++ b/src/generated/resources/assets/functionalstorage/models/item/compacting_framed_drawer.json @@ -0,0 +1,3 @@ +{ + "parent": "functionalstorage:block/compacting_framed_drawer" +} \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/loot_tables/blocks/compacting_framed_drawer.json b/src/generated/resources/data/functionalstorage/loot_tables/blocks/compacting_framed_drawer.json new file mode 100644 index 0000000..68701f9 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/loot_tables/blocks/compacting_framed_drawer.json @@ -0,0 +1,3 @@ +{ + "type": "minecraft:block" +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 03f3bd9..0db3f6e 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -2,6 +2,7 @@ "replace": false, "values": [ "functionalstorage:compacting_drawer", + "functionalstorage:compacting_framed_drawer", "functionalstorage:storage_controller", "functionalstorage:armory_cabinet", "functionalstorage:ender_drawer" diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index 15a59af..23ad51c 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -99,6 +99,7 @@ public class FunctionalStorage extends ModuleController { public static Pair, RegistryObject>> DRAWER_CONTROLLER; public static Pair, RegistryObject>> ARMORY_CABINET; public static Pair, RegistryObject>> ENDER_DRAWER; + public static Pair, RegistryObject>> FRAMED_COMPACTING_DRAWER; public static RegistryObject LINKING_TOOL; public static HashMap> 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) COMPACTING_DRAWER.getRight().get(), p_173571_ -> new CompactingDrawerRenderer()); + registerRenderers.registerBlockEntityRenderer((BlockEntityType) FRAMED_COMPACTING_DRAWER.getRight().get(), p_173571_ -> new CompactingDrawerRenderer()); registerRenderers.registerBlockEntityRenderer((BlockEntityType) DRAWER_CONTROLLER.getRight().get(), p -> new ControllerRenderer()); registerRenderers.registerBlockEntityRenderer((BlockEntityType) 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 -> { diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java new file mode 100644 index 0000000..61b8110 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java @@ -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 getTileEntityFactory() { + return (blockPos, state) -> new CompactingFramedDrawerTile(this, (BlockEntityType) 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 getDrops(BlockState p_60537_, LootContext.Builder builder) { + NonNullList 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 consumer) { + + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 0c15874..0d941e3 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -319,7 +319,7 @@ public class DrawerBlock extends RotatableBlock { @Override public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List 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("")); diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingFramedDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingFramedDrawerTile.java new file mode 100644 index 0000000..994a5a5 --- /dev/null +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingFramedDrawerTile.java @@ -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 base, BlockEntityType 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(); + } +} diff --git a/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java b/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java index b14e0eb..fb0dc7c 100644 --- a/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java +++ b/src/main/java/com/buuz135/functionalstorage/recipe/FramedDrawerRecipe.java @@ -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; diff --git a/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json b/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json new file mode 100644 index 0000000..d13f6d2 --- /dev/null +++ b/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json @@ -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] + } + } +} \ No newline at end of file From dc5e4436256c419fd111dac9b18459296c201cea Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Fri, 8 Jul 2022 23:05:55 +0200 Subject: [PATCH 5/7] Added Compacting Framed drawer recipe and framing explanation --- .../assets/functionalstorage/lang/en_us.json | 3 +- .../recipes/compacting_framed_drawer.json | 51 +++++++++++++++++++ .../functionalstorage/FunctionalStorage.java | 9 ++-- .../block/CompactingFramedDrawerBlock.java | 36 ++++++++----- .../block/FramedDrawerBlock.java | 14 +++-- .../data/FunctionalStorageLangProvider.java | 1 + 6 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 src/generated/resources/data/functionalstorage/recipes/compacting_framed_drawer.json diff --git a/src/generated/resources/assets/functionalstorage/lang/en_us.json b/src/generated/resources/assets/functionalstorage/lang/en_us.json index 17a78ac..701b46b 100644 --- a/src/generated/resources/assets/functionalstorage/lang/en_us.json +++ b/src/generated/resources/assets/functionalstorage/lang/en_us.json @@ -70,5 +70,6 @@ "storageupgrade.desc": "Multiplies the block storage by ", "upgrade.type": "Type: ", "upgrade.type.storage": "Storage", - "upgrade.type.utility": "Utility" + "upgrade.type.utility": "Utility", + "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" } \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/recipes/compacting_framed_drawer.json b/src/generated/resources/data/functionalstorage/recipes/compacting_framed_drawer.json new file mode 100644 index 0000000..a09a119 --- /dev/null +++ b/src/generated/resources/data/functionalstorage/recipes/compacting_framed_drawer.json @@ -0,0 +1,51 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "values": [ + { + "item": "functionalstorage:compacting_framed_drawer", + "type": "forge:item_exists" + } + ], + "type": "forge:and" + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "pattern": [ + "SSS", + "PDP", + "SIS" + ], + "key": { + "S": { + "item": "minecraft:stone" + }, + "P": { + "item": "minecraft:piston" + }, + "D": [ + { + "item": "functionalstorage:framed_1" + }, + { + "item": "functionalstorage:framed_2" + }, + { + "item": "functionalstorage:framed_4" + } + ], + "I": { + "tag": "forge:ingots/iron" + } + }, + "result": { + "item": "functionalstorage:compacting_framed_drawer" + } + } + } + ] +} \ 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 23ad51c..7acd7ce 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -22,7 +22,6 @@ import com.buuz135.functionalstorage.recipe.DrawerlessWoodIngredient; import com.buuz135.functionalstorage.recipe.FramedDrawerRecipe; import com.buuz135.functionalstorage.util.*; import com.hrznstudio.titanium.block.BasicBlock; -import com.hrznstudio.titanium.block.BasicTileBlock; import com.hrznstudio.titanium.datagenerator.loot.TitaniumLootTableProvider; import com.hrznstudio.titanium.datagenerator.model.BlockItemModelGeneratorProvider; import com.hrznstudio.titanium.event.handler.EventManager; @@ -154,10 +153,12 @@ public class FunctionalStorage extends ModuleController { WOOD_TYPES.addAll(List.of(DrawerWoodType.values())); for (DrawerType value : DrawerType.values()) { for (IWoodType woodType : WOOD_TYPES) { - String name = woodType.getName() + "_" + value.getSlots(); + var name = woodType.getName() + "_" + value.getSlots(); if (woodType == DrawerWoodType.FRAMED){ - DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new FramedDrawerBlock(value), blockRegistryObject -> () -> - new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); + var pair = getRegistries().registerBlockWithTileItem(name, () -> new FramedDrawerBlock(value), blockRegistryObject -> () -> + new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB))); + DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(pair); + CompactingFramedDrawerBlock.FRAMED.add(pair.getLeft()); } else { DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value), blockRegistryObject -> () -> new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java index 61b8110..9498e4c 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java @@ -3,24 +3,23 @@ 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.ChatFormatting; 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.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; 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.item.TooltipFlag; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -28,17 +27,17 @@ 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 net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{ + public static List> FRAMED = new ArrayList<>(); + public CompactingFramedDrawerBlock(String name) { super(name); } @@ -85,6 +84,17 @@ public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{ @Override public void registerRecipe(Consumer consumer) { - + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .pattern("SSS").pattern("PDP").pattern("SIS") + .define('S', Blocks.STONE) + .define('P', Blocks.PISTON) + .define('D', Ingredient.of(FRAMED.stream().map(itemSupplier -> new ItemStack(itemSupplier.get())))) + .define('I', Tags.Items.INGOTS_IRON) + .save(consumer); + } + @Override + public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List components, TooltipFlag p_49819_) { + components.add(new TranslatableComponent("frameddrawer.use").withStyle(ChatFormatting.GRAY)); + super.appendHoverText(p_49816_, p_49817_, components, p_49819_); } } diff --git a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java index 6d4a2ee..b64d3df 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java @@ -11,18 +11,18 @@ import com.buuz135.functionalstorage.util.IWoodType; import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; import com.hrznstudio.titanium.util.ItemHandlerUtil; import com.hrznstudio.titanium.util.TileUtil; +import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.tooltip.TooltipComponent; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; +import net.minecraft.world.item.*; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -136,4 +136,10 @@ public class FramedDrawerBlock extends DrawerBlock{ } } + + @Override + public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List components, TooltipFlag p_49819_) { + components.add(new TranslatableComponent("frameddrawer.use").withStyle(ChatFormatting.GRAY)); + super.appendHoverText(p_49816_, p_49817_, components, p_49819_); + } } diff --git a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java index 7c59044..455546a 100644 --- a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java +++ b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageLangProvider.java @@ -68,5 +68,6 @@ public class FunctionalStorageLangProvider extends LanguageProvider { this.add("linkingtool.ender.frequency", "Frequency: "); 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"); } } From 0b01c6eb197c2418a252cbd496bc157e205a0a8f Mon Sep 17 00:00:00 2001 From: Ridanis Date: Fri, 8 Jul 2022 23:30:49 +0200 Subject: [PATCH 6/7] Framed Drawers Textures --- .../textures/blocks/framed_front_2.png | Bin 0 -> 3786 bytes .../textures/blocks/framed_front_4.png | Bin 0 -> 3788 bytes .../textures/blocks/framed_front_comptacting.png | Bin 0 -> 3769 bytes .../textures/blocks/framed_side.png | Bin 0 -> 3778 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/functionalstorage/textures/blocks/framed_front_2.png create mode 100644 src/main/resources/assets/functionalstorage/textures/blocks/framed_front_4.png create mode 100644 src/main/resources/assets/functionalstorage/textures/blocks/framed_front_comptacting.png create mode 100644 src/main/resources/assets/functionalstorage/textures/blocks/framed_side.png diff --git a/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_2.png b/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8baa0d094d0ee61ca674d8c679d15b6fd292c2e4 GIT binary patch literal 3786 zcmcInZEPGz8NLJ(aDs(NB^p(sSvDvtgt?ua-I@I$m*V=8+O+2y$5ov+70k}e+N<2{ zUU%2_*%64EO1Ov?wSpA2Q3Fz-B2r8915^@1Rg$QJA_VCG>Z*0^lJ0McU6B9vLQZJr- zR#gICQt!YOSg8+)$zX6U7JKK0$JpEf=5Y1KUCPdeD+Saf8YXU|q&DTc@;MvU zRHX??50upYOrbJf8BqqJSSVHz0R|ydET@PG5gx-IR}e%ApiyWo>Q>D6? z`|fCYPg|LME2)!dT6Z;VW@e^1V-%x!Lem|`(ICNTR8jiQUsuql{o%8d(ZbV6wLaH6TLQgMgEB&8t}L*{j@VR2s%(8L!Fa@^jC?m-WJ3b6P5|1a1yfl?&`BhT&_TYF%)#_Ah&_Xitp{8g5?fHGH%r8#g9tJYRNL4bv zxJ~_gW$ls%5R47n9v=xBqB>p}%T_{^(XC{RV)>T;Bf+dlk&d^x&Psj+bnibkg#wT?8 z>ZT*h@r1ApAn!V$NOF@pIt1MCsb!m-S;+3Veue3>Y#Y$Uu#<4_#PoJp*(41ogzQ3^ z`p%un@=Vx12Zlj>p!+5PjxZ@8h9QVeC^m_Ig)=J^gl?TNmsY3NqHdgFQ8+E)CB&-J zn95En;-sYdaa2=iyJH`c4AkS_Pp5tXJxsiKl*RW zd&ZiaP;RG7^vnL0700AqRc@jad41Wnd{fdnwIMYiz|i-A4^0Rt#WwJ;Eqr7WBq-b2 z3~@DBO_qTisx#RiDVIG7JEj3VCIwmyVT61P9b4~K7BPLB`yK(<@&#}#(+8dj1;D0d zc$829IqFuHO?~Fuo)2t8Fu;k4fJbE?X0q#2gX<v5o9V;z&yz zB2Uz^jG7esOjro7yqb8v!+c5s#25n4$>MAHHlW0_4GZfw#P-UoyXl)tRyX<6BBOS7 z);5t#PXCf}%^~?okv--gGx8<>91@}IKC%4R`TPC>vrt%L50(4J><7+{p8C}3kWs=lh=i#Yu|cl%l^YhzTUs~hU8B_-oNRw zWapXf-+t?dFZVr`@Sp!?-Ox*~km~5M*Is?-J;$BrfB*bJZ}eE>1M80-(|+>F<0pRl v?D=z-e%E;9iyymh{Nlc!UFSUX{peld)Bj-4UH`T0YjbG#aQUg5K0E&}p7`Dq literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_4.png b/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_4.png new file mode 100644 index 0000000000000000000000000000000000000000..1c7f3bcc01e0ab85c48d650be9425e19f3e4c71d GIT binary patch literal 3788 zcmcgvdyL$~8Q;(m{3z12&wJgIrKWGoBgmx!JWH z+jqA~1-i6Qf=UYl0S5u`2PsG-0VN2jX?a#CN=0%CuLy~%MKoNC5CYVye>5WLcpttC z+~u~k>PlYQGr##>^ZUMUe8=FrtClVK_L4%Ouxwy$dA+#zWY^ahi~sNc{WKA`bECDJ zl0sqWdD*q7@X*5-2(aZ34X4AEYaJTai-d(PFE;9tKo<(VeT|6FEj*Q6UiE{L{PFKz zlqH{)uiBsb+c;yD{u zWT^>Bx0K}mOrbPf8I)FqF_+9D0u(|hnRXEy26rjGLP8KB1!4u-0GbX$4zi{8PZsK8 z<~i%jYud`hTS*>C)5uYj@$vEExK<3~s-oJqtw5w81Ox&k+k%udK#*MAkx=Fdjr}O~ z!$8U;5;q)8OR_MvlaZ9(5TM){qi2>q{@{js5Z4#D$YQVq$Hqxpj?uLsYTysj>Sw3>YfKQ z#5izO-2k>l4WJ{JB8_0=T1IDmIi#Z*sj~I01Y;o;GV0?wgyck5+5pR_TQf0w7~q#^!0%+LX2c7 zvViR?4yrb=LZc;M}%$t=Yi0 zwx4Rg)J#f;(3T4{V<%^Fd)S|2gS!i5OYHav7r{CUYg@1+^wMz>^Zu%c@Pb*P%x8Q; z#?Ed!GHsW0Qv>3z0)li7h^<1vG>@2;&Zvp3j_Y4AU6gGNIv92m?#r0o4l5lYL6wUx zq{v_18Pl{i0u2LD^xC-EvTLVn>wryx9L|Wx1t4{BO&9 z#+sZ^PNz%si~f}r$E00VR+4I7U#^_HDXENDkZ2HKm~|$oLqG_&fQv2eA>BZn(B5W< zYyLvAG-MN%irz+;=tOVq5`xCYUfs#CptSq$mAZa@G3(7Tz#3x1en19TOm;7^x2crAL;$!EX{{4QTu*exG_YYaW{PjKiul`DZ&(BXU zd*S8t?cW?-dg6PRNnbnvgW6ts$8)#dcH8cyD{uY5Z}ktpy1(ZaJD+{##!Gwty7}YF zkIN4xM?bpo*ozmw{phZf)#(i%9zFh8|D!)F6r9WUJ%7i#!n^+rZa6u4_`T_WE!p$H z#y|G;uKDb>XyX1}YvVZ+_dNOR;=<%-e}4aw!>2ykvv}b38>a5N>B(2#zxl)^{tEfS zXZG&dS;J%3c=1#Jc;gSl-`v#q$es5cDW1D??~jVpSO54e>Dptjp1kGY5V ziNOQ6Pd;&c*S_$*&H6y?WhUN%XhdFS_8~Q&atoLw#F&roQ`^iG$YE yj^&3IO`P6Zcz4&&29K=%X!rEQd7r*eIJM)P<##^*jpp~}!0L77r&ezM>AwNq8|ml( literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_comptacting.png b/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_comptacting.png new file mode 100644 index 0000000000000000000000000000000000000000..ef4cf134c304a1b986a4e52c010b212223c29548 GIT binary patch literal 3769 zcmcInZH(MT8QwGzO%p;xS{0~(7)PZIbk^gs$M#s+TraoR-qCDwx;xZM71WH!<2!S^ z>&5onZ32jh1l0872S}A#XetChBDLs1Em4Bnw2=@XL`C_Lg3_Xh4@FT$A(R#bK_a}~ z-Sb__ZEh*BlGpakGw;_t@B5CAjO@B=!@8T-6$*t7!$aj!xNpp^weN!e&2L`jaJ#NC zv?nPP*58m_s|sIx{QUrS!tsf8qO#K!QLV`R$dkoptpVslVOw9b!Ns&p6;Dov^^$t= z*%wqL^h@eJw1O**0XY>89f;-FfnDR`z_eh#+P7WV)^tHYO{QFF)~fZyZI;xQTo<0R zVNF$9kaW7F_Gb!}iOPsF5XDlliv$Ubv0}3#wJhlgdb>g}AsVI{W(eCZAueG`=cj_Y z*bm&%@|_)J@K#c%(zM}f+T7e+an2}4@ua3R#xzVcLJ%NOvcI14CaNb}79^BqBI2-- zhEZL~ByumBNlPl2+V-K=$i>!^PMjcOT9Y?4y@)fPT0mdqxW-IeZ7KJKCabb0>uCa5 zJ;y?rDwQ0*tk_yDMZCP|OzP};0QJF+Dv5rGuL$*p8$@x9!^VX*J}I?EeX^ykQgMgtNy_U&4wp+Rm|6@&-(?(|KGQAa z5X(k^ZU%_idVs7zFvttt(j8}EeK`^{8L6`M?F9290W$L4aHWvK@g+kJmO65nDUnBc zfVlKbn*_Sy_+&xa?l^=T=hdZBGpl@%D1~8CVpC*DY9bR%M2;mX;zCHw1eJn$sOncBK;2_rY?7uU=XNCF2=}*=}2r)R5 z@x^WFAA{Nj23V9Dv@<>uHf439975ERwjtKinLSs|WTh<2Py^o31;n_WzYvTb0O;)R5JC#H8~iz!~8l+cAV^_@Et zNXY_ISP1Kmi2`amh*PG6Z_IQswk0F^KIZ$-tswO3jJdQrwHNi`jEL&9GG0Qg29G&( zQW+;DHHf2{!W)fhC|cR2&DQ-+f65b5Nh4*k{B#YPFXM0t2bOBdO;G-a`c`CIZ`JT^ zjQjs@l9nA1+GRj{dxdDfm)nuNGuxY1<8_y-1-)_*I!Q%ruZEK%gxMB_yDjIeM?MEHiNYz_Spw0|{LhTCZnfiKuBC9=Eu} zKIv7K!vhgGUVt1!3glZRK^}*$E{JDw!`Dq=_AbjOrfFIjVUtN@cqT`V!x%CN6_zjr z5nj(e`o0H;X2r!O9(3nna0?rYp6eEvi@ihV{yO!q|Hq{+Wo$jl9>6=SdxA@a0qjq)HwvbCs z|3JCc5PVW(kNL+8yyTxlvJTxRhL4?7Cm(pOP*`>AaJhfndH9jByFanIf8*yr^jyF8 z?wuE|dF%&kH*LJJ|5qnR*Sz$Rp}k+aV-25u=CLjJuh;e+pWk#p{dw}hEPwLo?h{`< zvGvla*S>k~%=Gbd)zYTF{r2Vp*3TZi;e&J*0~>$A9TXdaiH#w=VtUb?4}zfA$?YfBMnekFI`0``yK( ztN(t-=YAZY-g_)5q?>m=vHM#0yPw@zzUkiS?;QWp`IjHQ_>aqXU(covegDJXKJ!+r czG82^yms`)FaPqI?BjBHa94SL$G$KA3wzkVsd+wY$bLL4e&9=AgZqwV=-L2ilKkS(^XLhH( zcV;>>yL-2gSSUu&P?aEw4N67YkQf^cN{nb5`$%n!hL@O-@Jyf(LKM&fd%fBm^!|!MQ`VoW6Rq^0> zS}I+=CjTxg9e(Ij0JehBv23ii)!|X2%)H1IoJ zEVUrn-ikbsJCw$1JERR!A|$g+5XTrxrd`$zL%3Y;mk1_A!McKNgiVJKhuBi*BZIrd z^PS=9rj9fCSCJ>PEOr!SW@e^5qm`p%LQ!qoRxnWrL4ZK%Y?!eo3e&!>g{nw-62w^$ zg;H*jxzSWsks;J}4vn}l8>XE)LB*6Nixstu^PE~hj~BRjDyg@edt4E9(GX#l0#+@s zP^Ma~fG=pa(J0Vqws9IF>g2W{Ivt&jg)%JCXe!}i<1~2e>jsu)!(y&9JuC-!u{fTL zvM8O57AZn8eMu>@z+c2+K643FG=oK;`Ah+goeha#S(J=MQN2r^9o^U@qLs09)2<-& zqM7uIdE%V~qRKK+k%34mQVAk>6k|sPBI!3{)xo$8tpPVZmazg%fNuy}qeOFncq)L& z960gPQnhMHJ^z8A1nRTwt5)g4+<)oZk&mJxXek z2Q}AZDc@}e%tNRwKVKDD?F^3PRIN|72TcM8A1iA9+nFCCbF&?-84>$BclAJO9ZHAs zb_zUar|{&?aInAz_g2cb*_lZJ#kvA(+psk9vl*6%feEPalBYshEcld7UpaJQ+O80$ zhTy6qMu1n$Rx$E4pP3f*xJj&T>X(HMvaMl9$K3<>aYFBul~1y8LO>T%3gNnp z7zlezN1RfMEM^(Vb6xCn>NBG8%aU145PD69&R3`QqF$2WQ8+DPM0zrdY%4M97rjPq&fLnv}m44f_WU6@1+Pq`XBmRl5xGMVY`q8Z5dGhT_M{4tL;i|%J-(#c%6l`pjQq;Cw4&E3$g#tWV!7>`fueuXH7vUr`sh4 zpnv7!n08cUJ)0=><<^CplIk%FGYumhLu2zX#fUN8LauHJpHPDc#@Dt=To0DAr4gH{ zoPiMKol>`{hFlH?O-^(|d>z}C+N&*t`j+Rr2GUJmAlsxqaw!%_r>5pIg9+@BUTs;- z=f36o(7Xk-TZ0nhGSxtwxCYZam2%p+tHeaE%dlZns;jzvd5&GaY1~i=SM#i(s)coH@zuTb&3UU^{ArU>xiV{8$azoyK)Kcs zyi(-1#mfx*DPD&}2;C=vmz|>zzjUNjT84+J1Ebb`M@N3U=iu&7RKEJ=4b}%|Pu%&k z_Q3tii8%jx`rM7-`X7xvxOM#Mqd(Yk!sZqwb%?>KW+>6PKPcKza-PnLdmTXfi`r{2G|`7873Kio|#?AZ44 z?`}RlaPP$5ANb&(%YOXofuZ}e@S0Qiyz#BiU4MOcy8qqgBY!?|Zq0q!>Cc{fZ{?x4 zpT6VgkN*0RV{dF#RzG(09{wUe|H2D9SDf7UlY_@^d2H$_vEupXk3FM&C|2~Z?7Qu! z=HRnyUV8ubW2*)l{pq%c&-IOb{m7GFdFKm*wX;)yBo}5synXzMoj1Pu&U@cK|Imfs zJdVEn+{_c-(@JOd-SxE#2khgUzr9`g{o^k#Gyk${_o26U{>eVH=B6zl)!)5g%d3y3 c|0ta(9X$2ynQ&!7^S8{QjoYfn*YCdTUszz|u>b%7 literal 0 HcmV?d00001 From edcb4cf47bd9babddcbff4a934b0ea43e1cd69b6 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sat, 9 Jul 2022 17:02:51 +0200 Subject: [PATCH 7/7] Added textures --- .../functionalstorage/FunctionalStorage.java | 6 +++-- .../block/CompactingDrawerBlock.java | 4 +-- .../block/CompactingFramedDrawerBlock.java | 5 ++-- .../functionalstorage/block/DrawerBlock.java | 6 +++-- .../block/FramedDrawerBlock.java | 9 +++++-- .../models/block/base_x_2_framed.json | 6 ++--- .../models/block/base_x_4_framed.json | 18 +++++++------- .../block/compacting_framed_drawer.json | 23 +++++++++--------- .../models/block/framed_1.json | 6 +++-- .../models/block/framed_2.json | 7 ++++-- .../models/block/framed_4.json | 7 ++++-- ...acting.png => framed_front_compacting.png} | Bin 12 files changed, 58 insertions(+), 39 deletions(-) rename src/main/resources/assets/functionalstorage/textures/blocks/{framed_front_comptacting.png => framed_front_compacting.png} (100%) diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index 7acd7ce..bd3e0f3 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -45,7 +45,9 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ColorHandlerEvent; @@ -160,13 +162,13 @@ public class FunctionalStorage extends ModuleController { DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(pair); CompactingFramedDrawerBlock.FRAMED.add(pair.getLeft()); } else { - DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value), blockRegistryObject -> () -> + DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value, BlockBehaviour.Properties.copy(woodType.getPlanks())), blockRegistryObject -> () -> new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); } } DRAWER_TYPES.get(value).forEach(blockRegistryObject -> TAB.addIconStacks(() -> new ItemStack(blockRegistryObject.getLeft().get()))); } - COMPACTING_DRAWER = getRegistries().registerBlockWithTile("compacting_drawer", () -> new CompactingDrawerBlock("compacting_drawer")); + COMPACTING_DRAWER = getRegistries().registerBlockWithTile("compacting_drawer", () -> new CompactingDrawerBlock("compacting_drawer", BlockBehaviour.Properties.copy(Blocks.STONE_BRICKS))); 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); diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java index 18f7336..b44cd50 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java @@ -70,8 +70,8 @@ public class CompactingDrawerBlock extends RotatableBlock } - public CompactingDrawerBlock(String name) { - super(name, Properties.copy(Blocks.STONE_BRICKS), CompactingDrawerTile.class); + public CompactingDrawerBlock(String name, Properties properties) { + super(name, properties, CompactingDrawerTile.class); setItemGroup(FunctionalStorage.TAB); registerDefaultState(defaultBlockState().setValue(RotatableBlock.FACING_HORIZONTAL, Direction.NORTH).setValue(DrawerBlock.LOCKED, false)); } diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java index 9498e4c..5c602cb 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingFramedDrawerBlock.java @@ -3,6 +3,7 @@ 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.FramedDrawerTile; import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; import com.hrznstudio.titanium.util.TileUtil; import net.minecraft.ChatFormatting; @@ -39,7 +40,7 @@ public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{ public static List> FRAMED = new ArrayList<>(); public CompactingFramedDrawerBlock(String name) { - super(name); + super(name, Properties.copy(Blocks.STONE).noOcclusion().isViewBlocking((p_61036_, p_61037_, p_61038_) -> false)); } @Override @@ -74,7 +75,7 @@ public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{ @Override public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) { BlockEntity entity = level.getBlockEntity(pos); - if (entity instanceof CompactingFramedDrawerTile framedDrawerTile){ + if (entity instanceof FramedDrawerTile framedDrawerTile && framedDrawerTile.getFramedDrawerModelData() != null && !framedDrawerTile.getFramedDrawerModelData().getDesign().isEmpty()){ ItemStack stack = new ItemStack(this); stack.getOrCreateTag().put("Style", framedDrawerTile.getFramedDrawerModelData().serializeNBT()); return stack; diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 0d941e3..3c1e481 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -38,6 +38,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; @@ -121,14 +122,15 @@ public class DrawerBlock extends RotatableBlock { private final FunctionalStorage.DrawerType type; private final IWoodType woodType; - public DrawerBlock(IWoodType woodType, FunctionalStorage.DrawerType type) { - super(woodType.getName() + "_" + type.getSlots(), Properties.copy(woodType.getPlanks()), DrawerTile.class); + public DrawerBlock(IWoodType woodType, FunctionalStorage.DrawerType type, BlockBehaviour.Properties properties) { + super(woodType.getName() + "_" + type.getSlots(), properties, DrawerTile.class); this.woodType = woodType; this.type = type; setItemGroup(FunctionalStorage.TAB); registerDefaultState(defaultBlockState().setValue(RotatableBlock.FACING_HORIZONTAL, Direction.NORTH).setValue(LOCKED, false)); } + @Override protected void createBlockStateDefinition(StateDefinition.Builder p_206840_1_) { super.createBlockStateDefinition(p_206840_1_); diff --git a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java index b64d3df..ea8cd2d 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/FramedDrawerBlock.java @@ -25,9 +25,12 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.*; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; 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.material.Material; +import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.HitResult; @@ -46,7 +49,7 @@ import java.util.function.Consumer; public class FramedDrawerBlock extends DrawerBlock{ public FramedDrawerBlock(FunctionalStorage.DrawerType type) { - super(DrawerWoodType.FRAMED, type); + super(DrawerWoodType.FRAMED, type, Properties.copy(Blocks.OAK_PLANKS).noOcclusion().isViewBlocking((p_61036_, p_61037_, p_61038_) -> false)); } @Override @@ -69,6 +72,7 @@ public class FramedDrawerBlock extends DrawerBlock{ data.put("particle", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("particle")))); data.put("front", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("front")))); data.put("side", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("side")))); + data.put("front_divider", ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("front_divider")))); return new FramedDrawerModelData(data); } return null; @@ -80,6 +84,7 @@ public class FramedDrawerBlock extends DrawerBlock{ style.putString("particle", first.getItem().getRegistryName().toString()); style.putString("side", first.getItem().getRegistryName().toString()); style.putString("front", second.getItem().getRegistryName().toString()); + style.putString("front_divider", first.getItem().getRegistryName().toString()); drawer.getOrCreateTag().put("Style", style); return drawer; } @@ -102,7 +107,7 @@ public class FramedDrawerBlock extends DrawerBlock{ @Override public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) { BlockEntity entity = level.getBlockEntity(pos); - if (entity instanceof FramedDrawerTile framedDrawerTile){ + if (entity instanceof FramedDrawerTile framedDrawerTile && framedDrawerTile.getFramedDrawerModelData() != null && !framedDrawerTile.getFramedDrawerModelData().getDesign().isEmpty()){ ItemStack stack = new ItemStack(this); stack.getOrCreateTag().put("Style", framedDrawerTile.getFramedDrawerModelData().serializeNBT()); return stack; diff --git a/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json b/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json index 24c380e..ddd75f5 100644 --- a/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json +++ b/src/main/resources/assets/functionalstorage/models/block/base_x_2_framed.json @@ -29,9 +29,9 @@ "to": [15, 9, 2], "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, "faces": { - "north": {"uv": [1, 7, 15, 9], "texture": "#side", "cullface": "north"}, - "up": {"uv": [15, 7, 1, 9], "texture": "#side"}, - "down": {"uv": [1, 9, 15, 7], "rotation": 180, "texture": "#side"} + "north": {"uv": [1, 7, 15, 9], "texture": "#front_divider", "cullface": "north"}, + "up": {"uv": [15, 7, 1, 9], "texture": "#front_divider"}, + "down": {"uv": [1, 9, 15, 7], "rotation": 180, "texture": "#front_divider"} } }, { diff --git a/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json b/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json index 3bad769..c5ca637 100644 --- a/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json +++ b/src/main/resources/assets/functionalstorage/models/block/base_x_4_framed.json @@ -50,9 +50,9 @@ "to": [9, 15, 2], "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, "faces": { - "north": {"uv": [7, 1, 9, 15], "texture": "#side", "cullface": "north"}, - "east": {"uv": [9, 1, 7, 15], "texture": "#side"}, - "west": {"uv": [9, 1, 7, 15], "texture": "#side"} + "north": {"uv": [7, 1, 9, 15], "texture": "#front_divider", "cullface": "north"}, + "east": {"uv": [9, 1, 7, 15], "texture": "#front_divider"}, + "west": {"uv": [9, 1, 7, 15], "texture": "#front_divider"} } }, { @@ -61,9 +61,9 @@ "to": [15, 9, 2], "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, "faces": { - "north": {"uv": [1, 7, 7, 9], "texture": "#side", "cullface": "north"}, - "up": {"uv": [7, 7, 1, 9], "texture": "#side"}, - "down": {"uv": [7, 7, 1, 9], "texture": "#side"} + "north": {"uv": [1, 7, 7, 9], "texture": "#front_divider", "cullface": "north"}, + "up": {"uv": [7, 7, 1, 9], "texture": "#front_divider"}, + "down": {"uv": [7, 7, 1, 9], "texture": "#front_divider"} } }, { @@ -72,9 +72,9 @@ "to": [7, 9, 2], "rotation": {"angle": 0, "axis": "y", "origin": [-8, 0, -8]}, "faces": { - "north": {"uv": [9, 7, 15, 9], "texture": "#side", "cullface": "north"}, - "up": {"uv": [15, 7, 9, 9], "texture": "#side"}, - "down": {"uv": [15, 7, 9, 9], "texture": "#side"} + "north": {"uv": [9, 7, 15, 9], "texture": "#front_divider", "cullface": "north"}, + "up": {"uv": [15, 7, 9, 9], "texture": "#front_divider"}, + "down": {"uv": [15, 7, 9, 9], "texture": "#front_divider"} } }, { diff --git a/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json b/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json index d13f6d2..110fc14 100644 --- a/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json +++ b/src/main/resources/assets/functionalstorage/models/block/compacting_framed_drawer.json @@ -2,12 +2,13 @@ "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", + "front": "functionalstorage:blocks/framed_side", + "particle": "functionalstorage:blocks/framed_side", + "side": "functionalstorage:blocks/framed_side", + "front_divider": "functionalstorage:blocks/framed_front_compacting", "lock_icon": "functionalstorage:blocks/unlock" }, - "retextured": [ "particle", "side", "front" ], + "retextured": [ "particle", "side", "front", "front_divider" ], "elements": [ { "from": [9, 1, 0.5], @@ -99,9 +100,9 @@ "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"} + "north": {"uv": [1, 7, 15, 9], "texture": "#front_divider", "cullface": "north"}, + "up": {"uv": [15, 8, 1, 7], "texture": "#front_divider"}, + "down": {"uv": [15, 8, 1, 9], "texture": "#front_divider"} } }, { @@ -109,10 +110,10 @@ "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"} + "north": {"uv": [7, 9, 9, 15], "texture": "#front_divider", "cullface": "north"}, + "east": {"uv": [7, 9, 8, 15], "texture": "#front_divider"}, + "south": {"uv": [0, 0, 2, 6], "texture": "#front_divider"}, + "west": {"uv": [8, 9, 9, 15], "texture": "#front_divider"} } }, { diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_1.json b/src/main/resources/assets/functionalstorage/models/block/framed_1.json index 134dcc0..28d22a1 100644 --- a/src/main/resources/assets/functionalstorage/models/block/framed_1.json +++ b/src/main/resources/assets/functionalstorage/models/block/framed_1.json @@ -2,7 +2,9 @@ "loader": "functionalstorage:framed", "parent": "functionalstorage:block/base_x_1", "textures": { - + "front": "functionalstorage:blocks/framed_side", + "particle": "functionalstorage:blocks/framed_side", + "side": "functionalstorage:blocks/framed_side" }, - "retextured": [ "particle", "side", "front" ] + "retextured": [ "particle", "side", "front", "front_divider" ] } \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_2.json b/src/main/resources/assets/functionalstorage/models/block/framed_2.json index 3db38e0..c70ee1b 100644 --- a/src/main/resources/assets/functionalstorage/models/block/framed_2.json +++ b/src/main/resources/assets/functionalstorage/models/block/framed_2.json @@ -2,7 +2,10 @@ "loader": "functionalstorage:framed", "parent": "functionalstorage:block/base_x_2_framed", "textures": { - + "front": "functionalstorage:blocks/framed_side", + "front_divider": "functionalstorage:blocks/framed_front_2", + "particle": "functionalstorage:blocks/framed_side", + "side": "functionalstorage:blocks/framed_side" }, - "retextured": [ "particle", "side", "front" ] + "retextured": [ "particle", "side", "front", "front_divider" ] } \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/models/block/framed_4.json b/src/main/resources/assets/functionalstorage/models/block/framed_4.json index 9e2e63b..b7d9650 100644 --- a/src/main/resources/assets/functionalstorage/models/block/framed_4.json +++ b/src/main/resources/assets/functionalstorage/models/block/framed_4.json @@ -2,7 +2,10 @@ "loader": "functionalstorage:framed", "parent": "functionalstorage:block/base_x_4_framed", "textures": { - + "front": "functionalstorage:blocks/framed_side", + "particle": "functionalstorage:blocks/framed_side", + "side": "functionalstorage:blocks/framed_side", + "front_divider": "functionalstorage:blocks/framed_front_4" }, - "retextured": [ "particle", "side", "front" ] + "retextured": [ "particle", "side", "front", "front_divider" ] } \ No newline at end of file diff --git a/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_comptacting.png b/src/main/resources/assets/functionalstorage/textures/blocks/framed_front_compacting.png similarity index 100% rename from src/main/resources/assets/functionalstorage/textures/blocks/framed_front_comptacting.png rename to src/main/resources/assets/functionalstorage/textures/blocks/framed_front_compacting.png