Skip to content

Commit

Permalink
cull sides of blocks if adjacent to same overall type
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Sep 21, 2023
1 parent 8bb06b0 commit 7bb3528
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/main/java/dev/upcraft/glassential/Glassential.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,8 @@ public class Glassential implements ModInitializer {
@SuppressWarnings("unused")
public static final RegistryKey<ItemGroup> GLASSENTIAL_ITEM_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(MODID, "items"));

public static final TagKey<Block> 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()
Expand All @@ -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> itemGroup) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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;
import net.minecraft.block.*;
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;
Expand All @@ -25,19 +29,21 @@ public class GlassentialGlassBlock extends AbstractGlassBlock {
private final boolean ethereal;
private final boolean redstone;
private final boolean reverseEthereal;
private final TagKey<Block> cullingTag;

public GlassentialGlassBlock(BlockProperties... properties) {
this(settings -> settings, properties);
public GlassentialGlassBlock(String cullId, BlockProperties... properties) {
this(settings -> settings, cullId, properties);
}

public GlassentialGlassBlock(UnaryOperator<AbstractBlock.Settings> settingsApplier, BlockProperties... properties) {
public GlassentialGlassBlock(UnaryOperator<AbstractBlock.Settings> settingsApplier, String cullId, BlockProperties... properties) {
super(settingsApplier.apply(FabricBlockSettings.copy(Blocks.GLASS)));
this.properties = properties;
List<BlockProperties> props = Arrays.asList(properties);
this.dark = props.contains(BlockProperties.TINTED);
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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"glassential:ethereal_glass",
"glassential:reverse_ethereal_glass"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"glassential:ghostly_glass"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"glassential:light_glass"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"glassential:redstone_glass"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"minecraft:tinted_glass",
"glassential:tinted_ethereal_glass",
"glassential:tinted_reverse_ethereal_glass"
]
}
5 changes: 4 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"fabric-api": "*",
"minecraft": "1.20.x",
"java": ">=17"
}
},
"mixins": [
"glassential.mixins.json"
]
}
12 changes: 12 additions & 0 deletions src/main/resources/glassential.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "dev.upcraft.glassential.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"TintedGlassBlockMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 7bb3528

Please sign in to comment.