Some NPE fixes for framed drawers, closes #69 nice
This commit is contained in:
parent
654a47e775
commit
19c6898ad0
|
@ -12,7 +12,7 @@ buildscript {
|
|||
apply plugin: 'net.minecraftforge.gradle'
|
||||
|
||||
group = 'com.buuz135'
|
||||
version = '1.18.2-1.0.0'
|
||||
version = '1.18.2-1.0.1'
|
||||
|
||||
java {
|
||||
archivesBaseName = 'functionalstorage'
|
||||
|
|
|
@ -152,7 +152,7 @@ d6b02c345edd356b8e4b7421bdd453f454c6ed7f data/functionalstorage/recipes/storage_
|
|||
bcb281904eac23183c45786e3d703d24bba92be6 data/functionalstorage/recipes/warped_1.json
|
||||
91e56e4558ed55571e9972bca1e8a1772655abdd data/functionalstorage/recipes/warped_2.json
|
||||
344de1ec16ecf9095fd5790c1c60a4014520829e data/functionalstorage/recipes/warped_4.json
|
||||
c63c5aa611d526d477655c15e0431da738d17e21 data/functionalstorage/tags/items/drawer.json
|
||||
a69dc275c6fb31a41441bbc2360001c68ec44281 data/functionalstorage/tags/items/drawer.json
|
||||
486a80437ce84b27a3d93db5134ea1fb4f66401f data/functionalstorage/tags/items/ignore_crafting_check.json
|
||||
c63c5aa611d526d477655c15e0431da738d17e21 data/minecraft/tags/blocks/mineable/axe.json
|
||||
2c1ca62408eae8963178024550b0771101e01d53 data/minecraft/tags/blocks/mineable/pickaxe.json
|
||||
a69dc275c6fb31a41441bbc2360001c68ec44281 data/minecraft/tags/blocks/mineable/axe.json
|
||||
38cb2a5ac786b577b097edc345083f9a1322b65e data/minecraft/tags/blocks/mineable/pickaxe.json
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"functionalstorage:oak_4",
|
||||
"functionalstorage:spruce_4",
|
||||
"functionalstorage:birch_4",
|
||||
"functionalstorage:jungle_4",
|
||||
"functionalstorage:acacia_4",
|
||||
"functionalstorage:dark_oak_4",
|
||||
"functionalstorage:crimson_4",
|
||||
"functionalstorage:warped_4",
|
||||
"functionalstorage:framed_4",
|
||||
"functionalstorage:oak_1",
|
||||
"functionalstorage:spruce_1",
|
||||
"functionalstorage:birch_1",
|
||||
|
@ -27,6 +18,15 @@
|
|||
"functionalstorage:dark_oak_2",
|
||||
"functionalstorage:crimson_2",
|
||||
"functionalstorage:warped_2",
|
||||
"functionalstorage:framed_2"
|
||||
"functionalstorage:framed_2",
|
||||
"functionalstorage:oak_4",
|
||||
"functionalstorage:spruce_4",
|
||||
"functionalstorage:birch_4",
|
||||
"functionalstorage:jungle_4",
|
||||
"functionalstorage:acacia_4",
|
||||
"functionalstorage:dark_oak_4",
|
||||
"functionalstorage:crimson_4",
|
||||
"functionalstorage:warped_4",
|
||||
"functionalstorage:framed_4"
|
||||
]
|
||||
}
|
|
@ -1,15 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"functionalstorage:oak_4",
|
||||
"functionalstorage:spruce_4",
|
||||
"functionalstorage:birch_4",
|
||||
"functionalstorage:jungle_4",
|
||||
"functionalstorage:acacia_4",
|
||||
"functionalstorage:dark_oak_4",
|
||||
"functionalstorage:crimson_4",
|
||||
"functionalstorage:warped_4",
|
||||
"functionalstorage:framed_4",
|
||||
"functionalstorage:oak_1",
|
||||
"functionalstorage:spruce_1",
|
||||
"functionalstorage:birch_1",
|
||||
|
@ -27,6 +18,15 @@
|
|||
"functionalstorage:dark_oak_2",
|
||||
"functionalstorage:crimson_2",
|
||||
"functionalstorage:warped_2",
|
||||
"functionalstorage:framed_2"
|
||||
"functionalstorage:framed_2",
|
||||
"functionalstorage:oak_4",
|
||||
"functionalstorage:spruce_4",
|
||||
"functionalstorage:birch_4",
|
||||
"functionalstorage:jungle_4",
|
||||
"functionalstorage:acacia_4",
|
||||
"functionalstorage:dark_oak_4",
|
||||
"functionalstorage:crimson_4",
|
||||
"functionalstorage:warped_4",
|
||||
"functionalstorage:framed_4"
|
||||
]
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"functionalstorage:compacting_drawer",
|
||||
"functionalstorage:storage_controller",
|
||||
"functionalstorage:armory_cabinet",
|
||||
"functionalstorage:ender_drawer"
|
||||
"functionalstorage:ender_drawer",
|
||||
"functionalstorage:compacting_framed_drawer"
|
||||
]
|
||||
}
|
|
@ -62,11 +62,13 @@ public class CompactingFramedDrawerBlock extends CompactingDrawerBlock{
|
|||
NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
ItemStack stack = new ItemStack(this);
|
||||
BlockEntity drawerTile = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
|
||||
if (drawerTile instanceof CompactingFramedDrawerTile) {
|
||||
if (!((CompactingFramedDrawerTile) drawerTile).isEverythingEmpty()) {
|
||||
if (drawerTile instanceof CompactingFramedDrawerTile framedDrawerTile) {
|
||||
if (!framedDrawerTile.isEverythingEmpty()) {
|
||||
stack.getOrCreateTag().put("Tile", drawerTile.saveWithoutMetadata());
|
||||
}
|
||||
stack.getOrCreateTag().put("Style", ((CompactingFramedDrawerTile) drawerTile).getFramedDrawerModelData().serializeNBT());
|
||||
if (framedDrawerTile.getFramedDrawerModelData() != null) {
|
||||
stack.getOrCreateTag().put("Style", framedDrawerTile.getFramedDrawerModelData().serializeNBT());
|
||||
}
|
||||
}
|
||||
stacks.add(stack);
|
||||
return stacks;
|
||||
|
|
|
@ -4,12 +4,8 @@ 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.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -21,21 +17,20 @@ 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.*;
|
||||
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.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;
|
||||
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;
|
||||
|
@ -43,7 +38,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FramedDrawerBlock extends DrawerBlock{
|
||||
|
@ -68,6 +62,7 @@ public class FramedDrawerBlock extends DrawerBlock{
|
|||
public static FramedDrawerModelData getDrawerModelData(ItemStack stack){
|
||||
if (stack.hasTag() && stack.getTag().contains("Style")){
|
||||
CompoundTag tag = stack.getTag().getCompound("Style");
|
||||
if (tag.isEmpty()) return null;
|
||||
HashMap<String, Item> 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"))));
|
||||
|
@ -94,11 +89,13 @@ public class FramedDrawerBlock extends DrawerBlock{
|
|||
NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
ItemStack stack = new ItemStack(this);
|
||||
BlockEntity drawerTile = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
|
||||
if (drawerTile instanceof FramedDrawerTile) {
|
||||
if (!((FramedDrawerTile) drawerTile).isEverythingEmpty()) {
|
||||
if (drawerTile instanceof FramedDrawerTile framedDrawerTile) {
|
||||
if (!framedDrawerTile.isEverythingEmpty()) {
|
||||
stack.getOrCreateTag().put("Tile", drawerTile.saveWithoutMetadata());
|
||||
}
|
||||
stack.getOrCreateTag().put("Style", ((FramedDrawerTile) drawerTile).getFramedDrawerModelData().serializeNBT());
|
||||
if (framedDrawerTile.getFramedDrawerModelData() != null) {
|
||||
stack.getOrCreateTag().put("Style", framedDrawerTile.getFramedDrawerModelData().serializeNBT());
|
||||
}
|
||||
}
|
||||
stacks.add(stack);
|
||||
return stacks;
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* 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<Pair<Pair<String, Pair<Direction, Direction>>, Direction>, List<BakedQuad>> CACHE = CacheBuilder.newBuilder().build();
|
||||
private VertexFormat format;
|
||||
private BakedModel previousModel;
|
||||
private Map<Direction, List<BakedQuad>> prevQuads = new HashMap<>();
|
||||
|
||||
public FramedDrawerBlockModel(BakedModel previousConveyor) {
|
||||
this.previousModel = previousConveyor;
|
||||
this.format = DefaultVertexFormat.BLOCK;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
|
||||
List<BakedQuad> 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<BakedQuad> 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();
|
||||
}
|
||||
}
|
|
@ -1,13 +1,9 @@
|
|||
package com.buuz135.functionalstorage.data;
|
||||
|
||||
import com.buuz135.functionalstorage.FunctionalStorage;
|
||||
import com.buuz135.functionalstorage.util.StorageTags;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
@ -30,6 +26,11 @@ public class FunctionalStorageBlockTagsProvider extends BlockTagsProvider {
|
|||
tTagAppender.add(blockRegistryObject.get());
|
||||
}
|
||||
}
|
||||
this.tag(BlockTags.MINEABLE_WITH_PICKAXE).add(FunctionalStorage.COMPACTING_DRAWER.getLeft().get()).add(FunctionalStorage.DRAWER_CONTROLLER.getLeft().get()).add(FunctionalStorage.ARMORY_CABINET.getLeft().get()).add(FunctionalStorage.ENDER_DRAWER.getLeft().get());
|
||||
this.tag(BlockTags.MINEABLE_WITH_PICKAXE)
|
||||
.add(FunctionalStorage.COMPACTING_DRAWER.getLeft().get())
|
||||
.add(FunctionalStorage.DRAWER_CONTROLLER.getLeft().get())
|
||||
.add(FunctionalStorage.ARMORY_CABINET.getLeft().get())
|
||||
.add(FunctionalStorage.ENDER_DRAWER.getLeft().get())
|
||||
.add(FunctionalStorage.FRAMED_COMPACTING_DRAWER.getLeft().get());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user