diff --git a/src/main/java/dev/upcraft/glassential/Glassential.java b/src/main/java/dev/upcraft/glassential/Glassential.java index c92f496..0dbe76d 100644 --- a/src/main/java/dev/upcraft/glassential/Glassential.java +++ b/src/main/java/dev/upcraft/glassential/Glassential.java @@ -13,6 +13,7 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.tag.TagKey; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -34,6 +35,8 @@ public class Glassential implements ModInitializer { @SuppressWarnings("unused") public static final RegistryKey GLASSENTIAL_ITEM_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(MODID, "items")); + public static final TagKey TINTED_GLASS_NO_CULL = TagKey.of(RegistryKeys.BLOCK, new Identifier(MODID, "no_cull/tinted")); + @Override public void onInitialize() { Registry.register(Registries.ITEM_GROUP, GLASSENTIAL_ITEM_GROUP, FabricItemGroup.builder() @@ -47,13 +50,13 @@ public void onInitialize() { .build() ); - TINTED_ETHEREAL_GLASS = registerBlock("tinted_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, BlockProperties.TINTED, BlockProperties.ETHEREAL)); - TINTED_REVERSE_ETHEREAL_GLASS = registerBlock("tinted_reverse_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, BlockProperties.TINTED, BlockProperties.REVERSE_ETHEREAL)); - ETHEREAL_GLASS = registerBlock("ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, BlockProperties.ETHEREAL)); - REVERSE_ETHEREAL_GLASS = registerBlock("reverse_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, BlockProperties.REVERSE_ETHEREAL)); - GHOSTLY_GLASS = registerBlock("ghostly_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, BlockProperties.GHOSTLY)); - LIGHT_GLASS = registerBlock("light_glass", new GlassentialGlassBlock(settings -> settings.luminance(state -> 15), BlockProperties.LUMINOUS)); - REDSTONE_GLASS = registerBlock("redstone_glass", new GlassentialGlassBlock(BlockProperties.REDSTONE), ItemGroups.REDSTONE); + TINTED_ETHEREAL_GLASS = registerBlock("tinted_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, "tinted", BlockProperties.TINTED, BlockProperties.ETHEREAL)); + TINTED_REVERSE_ETHEREAL_GLASS = registerBlock("tinted_reverse_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, "tinted", BlockProperties.TINTED, BlockProperties.REVERSE_ETHEREAL)); + ETHEREAL_GLASS = registerBlock("ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, "ethereal", BlockProperties.ETHEREAL)); + REVERSE_ETHEREAL_GLASS = registerBlock("reverse_ethereal_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, "ethereal", BlockProperties.REVERSE_ETHEREAL)); + GHOSTLY_GLASS = registerBlock("ghostly_glass", new GlassentialGlassBlock(AbstractBlock.Settings::noCollision, "ghostly", BlockProperties.GHOSTLY)); + LIGHT_GLASS = registerBlock("light_glass", new GlassentialGlassBlock(settings -> settings.luminance(state -> 15), "light", BlockProperties.LUMINOUS)); + REDSTONE_GLASS = registerBlock("redstone_glass", new GlassentialGlassBlock("redstone", BlockProperties.REDSTONE), ItemGroups.REDSTONE); } private static Block registerBlock(String name, Block block, @Nullable RegistryKey itemGroup) { diff --git a/src/main/java/dev/upcraft/glassential/blocks/GlassentialGlassBlock.java b/src/main/java/dev/upcraft/glassential/blocks/GlassentialGlassBlock.java index 74ba22b..48360c6 100644 --- a/src/main/java/dev/upcraft/glassential/blocks/GlassentialGlassBlock.java +++ b/src/main/java/dev/upcraft/glassential/blocks/GlassentialGlassBlock.java @@ -1,5 +1,6 @@ package dev.upcraft.glassential.blocks; +import dev.upcraft.glassential.Glassential; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -7,7 +8,10 @@ import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.item.ItemStack; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; @@ -25,12 +29,13 @@ public class GlassentialGlassBlock extends AbstractGlassBlock { private final boolean ethereal; private final boolean redstone; private final boolean reverseEthereal; + private final TagKey cullingTag; - public GlassentialGlassBlock(BlockProperties... properties) { - this(settings -> settings, properties); + public GlassentialGlassBlock(String cullId, BlockProperties... properties) { + this(settings -> settings, cullId, properties); } - public GlassentialGlassBlock(UnaryOperator settingsApplier, BlockProperties... properties) { + public GlassentialGlassBlock(UnaryOperator settingsApplier, String cullId, BlockProperties... properties) { super(settingsApplier.apply(FabricBlockSettings.copy(Blocks.GLASS))); this.properties = properties; List props = Arrays.asList(properties); @@ -38,6 +43,7 @@ public GlassentialGlassBlock(UnaryOperator settingsAppli this.ethereal = props.contains(BlockProperties.ETHEREAL); this.redstone = props.contains(BlockProperties.REDSTONE); this.reverseEthereal = !this.ethereal && props.contains(BlockProperties.REVERSE_ETHEREAL); + cullingTag = TagKey.of(RegistryKeys.BLOCK, new Identifier(Glassential.MODID, "no_cull/" + cullId)); } @Override @@ -80,4 +86,9 @@ public boolean emitsRedstonePower(BlockState state) { public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction direction) { return this.redstone ? 15 : super.getWeakRedstonePower(state, view, pos, direction); } + + @Override + public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + return stateFrom.isIn(cullingTag) || super.isSideInvisible(state, stateFrom, direction); + } } diff --git a/src/main/java/dev/upcraft/glassential/mixin/TintedGlassBlockMixin.java b/src/main/java/dev/upcraft/glassential/mixin/TintedGlassBlockMixin.java new file mode 100644 index 0000000..dd06491 --- /dev/null +++ b/src/main/java/dev/upcraft/glassential/mixin/TintedGlassBlockMixin.java @@ -0,0 +1,22 @@ +package dev.upcraft.glassential.mixin; + +import dev.upcraft.glassential.Glassential; +import net.minecraft.block.AbstractGlassBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.TintedGlassBlock; +import net.minecraft.util.math.Direction; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(TintedGlassBlock.class) +public abstract class TintedGlassBlockMixin extends AbstractGlassBlock { + + private TintedGlassBlockMixin(Settings settings) { + super(settings); + throw new UnsupportedOperationException(); + } + + @Override + public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + return stateFrom.isIn(Glassential.TINTED_GLASS_NO_CULL) || super.isSideInvisible(state, stateFrom, direction); + } +} diff --git a/src/main/resources/data/glassential/tags/blocks/no_cull/ethereal.json b/src/main/resources/data/glassential/tags/blocks/no_cull/ethereal.json new file mode 100644 index 0000000..0cd2b0e --- /dev/null +++ b/src/main/resources/data/glassential/tags/blocks/no_cull/ethereal.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "glassential:ethereal_glass", + "glassential:reverse_ethereal_glass" + ] +} diff --git a/src/main/resources/data/glassential/tags/blocks/no_cull/ghostly.json b/src/main/resources/data/glassential/tags/blocks/no_cull/ghostly.json new file mode 100644 index 0000000..832433b --- /dev/null +++ b/src/main/resources/data/glassential/tags/blocks/no_cull/ghostly.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "glassential:ghostly_glass" + ] +} diff --git a/src/main/resources/data/glassential/tags/blocks/no_cull/light.json b/src/main/resources/data/glassential/tags/blocks/no_cull/light.json new file mode 100644 index 0000000..3cd1ce1 --- /dev/null +++ b/src/main/resources/data/glassential/tags/blocks/no_cull/light.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "glassential:light_glass" + ] +} diff --git a/src/main/resources/data/glassential/tags/blocks/no_cull/redstone.json b/src/main/resources/data/glassential/tags/blocks/no_cull/redstone.json new file mode 100644 index 0000000..e4857a2 --- /dev/null +++ b/src/main/resources/data/glassential/tags/blocks/no_cull/redstone.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "glassential:redstone_glass" + ] +} diff --git a/src/main/resources/data/glassential/tags/blocks/no_cull/tinted.json b/src/main/resources/data/glassential/tags/blocks/no_cull/tinted.json new file mode 100644 index 0000000..bee690b --- /dev/null +++ b/src/main/resources/data/glassential/tags/blocks/no_cull/tinted.json @@ -0,0 +1,8 @@ +{ + "replace": false, + "values": [ + "minecraft:tinted_glass", + "glassential:tinted_ethereal_glass", + "glassential:tinted_reverse_ethereal_glass" + ] +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d979307..f9090d2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -38,5 +38,8 @@ "fabric-api": "*", "minecraft": "1.20.x", "java": ">=17" - } + }, + "mixins": [ + "glassential.mixins.json" + ] } diff --git a/src/main/resources/glassential.mixins.json b/src/main/resources/glassential.mixins.json new file mode 100644 index 0000000..7ac981a --- /dev/null +++ b/src/main/resources/glassential.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.upcraft.glassential.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "TintedGlassBlockMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}