Skip to content

Commit bf2e8c7

Browse files
committed
connected textures support
1 parent bb79088 commit bf2e8c7

17 files changed

Lines changed: 142 additions & 44 deletions

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ dependencies {
122122
implementation "curse.maven:productivebees-377897:5611632"
123123
implementation "curse.maven:storage-drawers-223852:5633810"
124124
implementation "curse.maven:mekanism-268560:5574951"
125+
implementation "curse.maven:fusion-connected-textures-854949:6183288"
126+
implementation "curse.maven:dyenamics-509276:6137368"
125127

126128
// Example optional mod dependency with JEI
127129
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1.21.1-0.2.0
2+
3+
- Added support for connected textures

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod_name=Camol
3434
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
3535
mod_license=All Rights Reserved
3636
# The mod version. See https://semver.org/
37-
mod_version=1.21.1-0.1.0
37+
mod_version=1.21.1-0.2.0
3838
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
3939
# This should match the base package used for the mod sources.
4040
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

src/main/java/cy/jdkdigital/camol/Camol.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ public class Camol
5959
public static final Supplier<DataComponentType<BlockState>> BLOCK_COMPONENT = DATA_COMPONENTS.register("block", () -> DataComponentType.<BlockState>builder().persistent(BlockState.CODEC).networkSynchronized(ByteBufCodecs.fromCodec(BlockState.CODEC)).build());
6060

6161
public static final Supplier<AttachmentType<Map<String, BlockState>>> CAMO_BLOCK_MAP = ATTACHMENT_TYPES.register(
62-
"camo", () -> AttachmentType.<Map<String, BlockState>>builder(() -> new HashMap<>()).serialize(Codec.unboundedMap(Codec.STRING, BlockState.CODEC)).build()
62+
"camo", () -> AttachmentType.<Map<String, BlockState>>builder(() -> new HashMap<>()).serialize(Codec.unboundedMap(Codec.STRING, BlockState.CODEC)).build()
6363
);
6464

6565
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<?>> SIMPLE_CAMO_CRAFTING = RECIPE_SERIALIZERS.register("simple_camo_crafting", () -> new SimpleCraftingRecipeSerializer<>(SimpleCamoCraftingRecipe::new));
66-
public static final DeferredHolder<RecipeType<?>, RecipeType<SimpleCamoCraftingRecipe>> SIMPLE_CAMO_CRAFTING_TYPE = RECIPE_TYPES.register("simple_camo_crafting", () -> new RecipeType<>() {});
66+
public static final DeferredHolder<RecipeType<?>, RecipeType<SimpleCamoCraftingRecipe>> SIMPLE_CAMO_CRAFTING_TYPE = RECIPE_TYPES.register("simple_camo_crafting", () -> new RecipeType<>()
67+
{
68+
});
6769

6870
public static final TagKey<Block> CAMO_BLACKLIST = BlockTags.create(ResourceLocation.fromNamespaceAndPath(MODID, "disallowed_camoable_blocks"));
6971
public static final TagKey<Item> CRAFTING_BLACKLIST = ItemTags.create(ResourceLocation.fromNamespaceAndPath(MODID, "disallowed_camo_blocks"));
7072

71-
public Camol(IEventBus modEventBus, ModContainer modContainer)
72-
{
73+
public Camol(IEventBus modEventBus, ModContainer modContainer) {
7374
ITEMS.register(modEventBus);
7475
BLOCKS.register(modEventBus);
7576
BLOCK_ENTITIES.register(modEventBus);
@@ -91,8 +92,7 @@ public Camol(IEventBus modEventBus, ModContainer modContainer)
9192
}
9293

9394
// Add the example block item to the building blocks tab
94-
private void addCreative(BuildCreativeModeTabContentsEvent event)
95-
{
95+
private void addCreative(BuildCreativeModeTabContentsEvent event) {
9696
if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
9797
ITEMS.getEntries().forEach(itemDeferredHolder -> {
9898
event.accept(itemDeferredHolder.value());

src/main/java/cy/jdkdigital/camol/Config.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class Config
1313
static final ModConfigSpec SPEC = BUILDER.build();
1414

1515
@SubscribeEvent
16-
static void onLoad(final ModConfigEvent event)
17-
{
16+
static void onLoad(final ModConfigEvent event) {
1817
}
1918
}

src/main/java/cy/jdkdigital/camol/common/item/CamoItem.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.world.item.context.UseOnContext;
1414
import net.minecraft.world.level.ChunkPos;
1515
import net.minecraft.world.level.block.Block;
16+
import net.minecraft.world.level.block.Blocks;
1617
import net.minecraft.world.level.block.state.BlockState;
1718
import net.minecraft.world.phys.BlockHitResult;
1819
import net.neoforged.neoforge.network.PacketDistributor;
@@ -32,10 +33,10 @@ public InteractionResult useOn(UseOnContext context) {
3233
String posKey = String.valueOf(context.getClickedPos().asLong());
3334
var chunk = serverLevel.getChunkAt(context.getClickedPos());
3435
var camoData = new HashMap<>(chunk.getData(Camol.CAMO_BLOCK_MAP));
35-
if (camoData.containsKey(posKey)) {
36+
if (camoData.containsKey(posKey) && !camoData.get(posKey).isAir()) {
3637
var camoState = camoData.get(posKey);
3738
Block.popResourceFromFace(serverLevel, context.getClickedPos(), context.getClickedFace(), getCamoItem(camoState));
38-
camoData.remove(posKey);
39+
camoData.put(posKey, Blocks.AIR.defaultBlockState());
3940
} else {
4041
var camoState = context.getItemInHand().get(Camol.BLOCK_COMPONENT);
4142
if (camoState != null) {

src/main/java/cy/jdkdigital/camol/common/recipe/SimpleCamoCraftingRecipe.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
public class SimpleCamoCraftingRecipe implements CraftingRecipe
1515
{
16-
public SimpleCamoCraftingRecipe(CraftingBookCategory category) {}
16+
public SimpleCamoCraftingRecipe(CraftingBookCategory category) {
17+
}
1718

1819
@Override
1920
public CraftingBookCategory category() {

src/main/java/cy/jdkdigital/camol/datagen/RecipeProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ protected void buildRecipes(RecipeOutput pRecipeOutput) {
3535
}
3636

3737
private static ResourceLocation prefixedRecipeId(ItemLike item, String prefix) {
38-
return BuiltInRegistries.ITEM.getKey(item.asItem()).withPath(path -> prefix + path);
38+
return BuiltInRegistries.ITEM.getKey(item.asItem()).withPath(path -> prefix + path);
3939
}
4040
}

src/main/java/cy/jdkdigital/camol/event/ClientEventHandler.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.vertex.PoseStack;
44
import com.mojang.blaze3d.vertex.VertexConsumer;
55
import cy.jdkdigital.camol.Camol;
6+
import cy.jdkdigital.camol.utils.CamoHelper;
67
import net.minecraft.client.Minecraft;
78
import net.minecraft.client.renderer.RenderType;
89
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
@@ -13,7 +14,7 @@
1314
import net.minecraft.world.InteractionHand;
1415
import net.minecraft.world.level.BlockAndTintGetter;
1516
import net.minecraft.world.level.block.state.BlockState;
16-
import net.minecraft.world.level.chunk.LevelChunk;
17+
import net.minecraft.world.phys.shapes.Shapes;
1718
import net.neoforged.api.distmarker.Dist;
1819
import net.neoforged.bus.api.SubscribeEvent;
1920
import net.neoforged.fml.common.EventBusSubscriber;
@@ -23,37 +24,31 @@
2324
import net.neoforged.neoforge.client.model.pipeline.VertexConsumerWrapper;
2425
import org.jetbrains.annotations.NotNull;
2526

26-
import java.util.*;
27+
import java.util.HashSet;
28+
import java.util.Map;
29+
import java.util.Set;
2730
import java.util.stream.Collectors;
2831

2932
@EventBusSubscriber(modid = Camol.MODID, value = Dist.CLIENT)
3033
public class ClientEventHandler
3134
{
3235
public static boolean shouldBeTransparent = false;
3336
public static boolean isTransparent = false;
37+
3438
@SubscribeEvent
3539
public static void onRenderLevelStage(RenderLevelStageEvent event) {
3640
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_TRANSLUCENT_BLOCKS) {
3741
return;
3842
}
3943

44+
// Change transparency of camo blocks when switching items in hand
4045
if (Minecraft.getInstance().level != null && shouldBeTransparent != isTransparent) {
4146
isTransparent = shouldBeTransparent;
4247
Set<SectionPos> sections = new HashSet<>();
4348

44-
var chunkStorage = Minecraft.getInstance().level.getChunkSource().storage;
45-
46-
int i = chunkStorage.chunkRadius;
47-
for (int j = chunkStorage.viewCenterZ - i; j <= chunkStorage.viewCenterZ + i; j++) {
48-
for (int k = chunkStorage.viewCenterX - i; k <= chunkStorage.viewCenterX + i; k++) {
49-
LevelChunk levelchunk = chunkStorage.chunks.get(chunkStorage.getIndex(k, j));
50-
if (levelchunk != null) {
51-
levelchunk.getData(Camol.CAMO_BLOCK_MAP).keySet().forEach(posKey -> {
52-
sections.add(SectionPos.of(BlockPos.of((Long.parseLong(posKey)))));
53-
});
54-
}
55-
}
56-
}
49+
CamoHelper.CLIENT_CAMO_MAP.entrySet().stream().filter(entry -> !entry.getValue().isAir()).forEach(entry -> {
50+
sections.add(SectionPos.of(BlockPos.of((Long.parseLong(entry.getKey())))));
51+
});
5752

5853
for (SectionPos section : sections) {
5954
Minecraft.getInstance().levelRenderer.setSectionDirty(section.x(), section.y(), section.z());
@@ -65,7 +60,8 @@ public static void onRenderLevelStage(RenderLevelStageEvent event) {
6560
public static void geometryEvent(AddSectionGeometryEvent event) {
6661
SectionPos section = SectionPos.of(event.getSectionOrigin());
6762

68-
Map<BlockPos, BlockState> camoBlocks = event.getLevel().getChunkAt(event.getSectionOrigin()).getData(Camol.CAMO_BLOCK_MAP).entrySet().stream()
63+
Map<BlockPos, BlockState> camoBlocks = CamoHelper.CLIENT_CAMO_MAP.entrySet().stream()
64+
.filter(entry -> !entry.getValue().isAir())
6965
.filter(p -> SectionPos.of(BlockPos.of(Long.parseLong(p.getKey()))).equals(section))
7066
.collect(Collectors.toMap(e -> BlockPos.of(Long.parseLong(e.getKey())), Map.Entry::getValue));
7167

@@ -86,9 +82,11 @@ public static void geometryEvent(AddSectionGeometryEvent event) {
8682
poseStack.pushPose();
8783
poseStack.translate(SectionPos.sectionRelative(pos.getX()), SectionPos.sectionRelative(pos.getY()), SectionPos.sectionRelative(pos.getZ()));
8884

89-
poseStack.translate(0.5, 0.5, 0.5);
90-
poseStack.scale(1.005F, 1.005F, 1.005F);
91-
poseStack.translate(-0.5, -0.5, -0.5);
85+
// if (level.getBlockState(pos).getShape(level, pos).equals(Shapes.block())) {
86+
poseStack.translate(0.5, 0.5, 0.5);
87+
poseStack.scale(1.005F, 1.005F, 1.005F);
88+
poseStack.translate(-0.5, -0.5, -0.5);
89+
// }
9290

9391
boolean shouldRenderTransparentCamo = Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND).is(Camol.CAMO_ITEM);
9492
for (RenderType renderType : model.getRenderTypes(camoState, random, ModelData.EMPTY)) {

src/main/java/cy/jdkdigital/camol/event/ClientModEventHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
1515

1616
@EventBusSubscriber(modid = Camol.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
17-
public class ClientModEventHandler {
17+
public class ClientModEventHandler
18+
{
1819
@SubscribeEvent
1920
public static void registerClientExtensions(RegisterClientExtensionsEvent event) {
20-
event.registerItem(new IClientItemExtensions() {
21+
event.registerItem(new IClientItemExtensions()
22+
{
2123
final BlockEntityWithoutLevelRenderer myRenderer = new CamoItemRenderer();
2224

2325
@Override

0 commit comments

Comments
 (0)