Skip to content

Commit afbf783

Browse files
committed
Fix crashes with invalid camo blocks
Also added `modularrouters:camo_blacklist` block tag #232
1 parent 3597e84 commit afbf783

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"values": []
3+
}

src/main/java/me/desht/modularrouters/ModularRoutersTags.java

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.tags.TagKey;
66
import net.minecraft.world.entity.EntityType;
77
import net.minecraft.world.item.Item;
8+
import net.minecraft.world.level.block.Block;
89

910
public class ModularRoutersTags {
1011
public static class Items {
@@ -18,6 +19,14 @@ private static TagKey<Item> modTag(String name) {
1819
}
1920
}
2021

22+
public static class Blocks {
23+
public static final TagKey<Block> CAMO_BLACKLIST = modTag("camo_blacklist");
24+
25+
private static TagKey<Block> modTag(String name) {
26+
return TagKey.create(Registries.BLOCK, MiscUtil.RL(name));
27+
}
28+
}
29+
2130
public static class EntityTypes {
2231
public static final TagKey<EntityType<?>> activatorInteractBlacklist = modTag("activator_interact_blacklist");
2332
public static final TagKey<EntityType<?>> activatorAttackBlacklist = modTag("activator_attack_blacklist");

src/main/java/me/desht/modularrouters/block/CamouflageableBlock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, Bloc
8787
ICamouflageable getCamoState(BlockGetter blockAccess, BlockPos pos) {
8888
if (blockAccess == null || pos == null) return null;
8989
BlockEntity te = blockAccess.getBlockEntity(pos);
90-
return te instanceof ICamouflageable c && c.getCamouflage() != null ? c : null;
90+
return te instanceof ICamouflageable c && c.getCamouflage() != null && !(c.getCamouflage().getBlock() instanceof CamouflageableBlock) ? c : null;
9191
}
9292

9393
@Override

src/main/java/me/desht/modularrouters/client/model/CamouflagingModel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public abstract class CamouflagingModel implements IDynamicBakedModel {
3636
if (renderType == null) {
3737
renderType = RenderType.solid(); // workaround for when this isn't set (digging, etc.)
3838
}
39-
if (camoState == null && renderType == RenderType.solid()) {
40-
// No camo
39+
if ((camoState == null || camoState.getBlock() instanceof CamouflageableBlock) && renderType == RenderType.solid()) {
40+
// No camo (or bad camo!)
4141
return baseModel.getQuads(state, side, rand, modelData, renderType);
4242
} else if (camoState != null && getRenderTypes(camoState, rand, modelData).contains(renderType)) {
4343
// Steal camo's model

src/main/java/me/desht/modularrouters/datagen/ModBlockTagsProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.desht.modularrouters.datagen;
22

33
import me.desht.modularrouters.ModularRouters;
4+
import me.desht.modularrouters.ModularRoutersTags;
45
import me.desht.modularrouters.core.ModBlocks;
56
import net.minecraft.core.HolderLookup;
67
import net.minecraft.data.DataGenerator;
@@ -20,5 +21,7 @@ public ModBlockTagsProvider(DataGenerator dataGenerator, CompletableFuture<Holde
2021
protected void addTags(HolderLookup.Provider provider) {
2122
tag(BlockTags.MINEABLE_WITH_PICKAXE).add(ModBlocks.MODULAR_ROUTER.get());
2223
tag(BlockTags.NEEDS_IRON_TOOL).add(ModBlocks.MODULAR_ROUTER.get());
24+
25+
tag(ModularRoutersTags.Blocks.CAMO_BLACKLIST);
2326
}
2427
}

src/main/java/me/desht/modularrouters/item/upgrade/CamouflageUpgrade.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.desht.modularrouters.item.upgrade;
22

3+
import me.desht.modularrouters.ModularRoutersTags;
4+
import me.desht.modularrouters.block.CamouflageableBlock;
35
import me.desht.modularrouters.block.tile.ModularRouterBlockEntity;
46
import me.desht.modularrouters.config.ConfigHolder;
57
import me.desht.modularrouters.core.ModBlocks;
@@ -62,6 +64,7 @@ public InteractionResult useOn(UseOnContext ctx) {
6264
return InteractionResult.SUCCESS;
6365
} else if (ctx.getLevel().isClientSide) {
6466
player.playSound(ModSounds.ERROR.get(), 1.0f, 1.0f);
67+
player.displayClientMessage(Component.translatable("modularrouters.chatText.misc.badCamoBlock").withStyle(ChatFormatting.RED), true);
6568
return InteractionResult.FAIL;
6669
}
6770
return InteractionResult.PASS;
@@ -79,8 +82,9 @@ public Component getName(ItemStack stack) {
7982
}
8083

8184
private static boolean isBlockOKForCamo(BlockState state) {
82-
// trying to camo a router as itself = recursion hell
83-
return state.getRenderShape() == RenderShape.MODEL && state.getBlock() != ModBlocks.MODULAR_ROUTER.get()
85+
// trying to camo a router as another camo block = recursion hell
86+
return state.getRenderShape() == RenderShape.MODEL && !(state.getBlock() instanceof CamouflageableBlock)
87+
&& !state.is(ModularRoutersTags.Blocks.CAMO_BLACKLIST)
8488
&& !BuiltInRegistries.BLOCK.getKey(state.getBlock()).getNamespace().equals("chiselsandbits");
8589
}
8690
}

src/main/resources/assets/modularrouters/lang/en_us.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"key.modularrouters.category" : "Modular Routers",
5959
"key.modularrouters.configure" : "Configure Installed Module (GUI)",
6060
"key.modularrouters.moduleInfo" : "Extra Tooltip Info (GUI)",
61+
"modularrouters.chatText.misc.badCamoBlock" : "Invalid camouflage block!",
6162
"modularrouters.chatText.misc.inventoryMerged" : "Merged %d item(s) into the %s",
6263
"modularrouters.chatText.misc.targetAdded" : "Target added (%d/%d): ",
6364
"modularrouters.chatText.misc.targetCleared" : "Target cleared",

0 commit comments

Comments
 (0)