Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bubble columns #40

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/xyz/amymialee/visiblebarriers/VisibleBarriers.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class VisibleBarriers implements ClientModInitializer {
protected static boolean toggleBarriers = false;
protected static boolean toggleLights = false;
protected static boolean toggleStructureVoids = false;
protected static boolean toggleBubbleColumns = false;
protected static boolean toggleFullBright = false;
protected static boolean toggleTime = false;
protected static boolean holdingZoom = false;
Expand All @@ -44,6 +45,7 @@ public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(Blocks.CAVE_AIR, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(Blocks.VOID_AIR, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(Blocks.MOVING_PISTON, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(Blocks.BUBBLE_COLUMN, RenderLayer.getTranslucent());
}

public static void sendFeedback(String translatable, Object... args) {
Expand Down Expand Up @@ -145,6 +147,20 @@ public static void setStructureVoids(boolean structureVoids) {
reloadWorldRenderer();
}

public static boolean areBubbleColumnsEnabled() {
return toggleBubbleColumns;
}

public static void toggleBubbleColumns() {
setBubbleColumns(!toggleBubbleColumns);
}

public static void setBubbleColumns(boolean bubbleColumns) {
toggleBubbleColumns = bubbleColumns;
booleanFeedback("visiblebarriers.feedback.bubblecolumns", toggleBubbleColumns);
reloadWorldRenderer();
}

public static Weather getWeather() {
return setWeather;
}
Expand Down Expand Up @@ -176,6 +192,13 @@ public static void modifyZoomModifier(float amount) {
}
return 0.0F;
});
ModelPredicateProviderRegistry.register(VisibleBarriersCommon.BUBBLE_COLUMN_BLOCK_ITEM, new Identifier("drag"), (stack, world, entity, seed) -> {
NbtCompound compound = stack.getSubNbt("BlockStateTag");
if (compound != null && Objects.equals(compound.getString("drag"), "true")) {
return 1.0F;
}
return 0.0F;
});
}

public enum Weather {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/xyz/amymialee/visiblebarriers/VisibleInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class VisibleInput {
private static KeyBinding keyBindingBarriers;
private static KeyBinding keyBindingLights;
private static KeyBinding keyBindingStructureVoids;
private static KeyBinding keyBindingBubbleColumns;
private static KeyBinding keyBindingFullBright;
private static KeyBinding keyBindingTime;
private static KeyBinding keyBindingZoom;
Expand All @@ -42,6 +43,11 @@ public static void initKeys() {
InputUtil.UNKNOWN_KEY.getCode(),
"category.visiblebarriers"
));
keyBindingBubbleColumns = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.visiblebarriers.bubblecolumns",
InputUtil.UNKNOWN_KEY.getCode(),
"category.bubblecolumns"
));
keyBindingFullBright = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.visiblebarriers.fullbright",
InputUtil.GLFW_KEY_M,
Expand Down Expand Up @@ -71,6 +77,9 @@ public static void initKeys() {
if (keyBindingStructureVoids.wasPressed()) {
VisibleBarriers.toggleStructureVoids();
}
if (keyBindingBubbleColumns.wasPressed()) {
VisibleBarriers.toggleBubbleColumns();
}
if (keyBindingFullBright.wasPressed()) {
VisibleBarriers.toggleFullBright();
}
Expand Down Expand Up @@ -143,6 +152,16 @@ public static void initCommands() {
VisibleBarriers.booleanFeedback("visiblebarriers.feedback.structurevoids", VisibleBarriers.toggleStructureVoids);
return 1;
})))
//Bubble columns
.then(ClientCommandManager.literal("bubblecolumns").executes(context -> {
VisibleBarriers.toggleStructureVoids();
return 1;
}).then(ClientCommandManager.argument("visible", BoolArgumentType.bool()).executes(context -> {
VisibleBarriers.toggleBubbleColumns = BoolArgumentType.getBool(context, "visible");
VisibleBarriers.reloadWorldRenderer();
VisibleBarriers.booleanFeedback("visiblebarriers.feedback.bubblecolumns", VisibleBarriers.toggleBubbleColumns);
return 1;
})))
)
//Fullbright
.then(ClientCommandManager.literal("fullbright").executes(context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.PistonExtensionBlock;
import net.minecraft.block.enums.PistonType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -30,29 +31,36 @@ public class VisibleBarriersCommon implements ModInitializer {
public static final BlockItem VOID_AIR_BLOCK_ITEM = Registry.register(Registries.ITEM, id("void_air"), new BlockItem(Blocks.VOID_AIR, new FabricItemSettings().rarity(Rarity.EPIC)));
public static final BlockItem END_PORTAL_BLOCK_ITEM = Registry.register(Registries.ITEM, id("end_portal"), new BlockItem(Blocks.END_PORTAL, new FabricItemSettings().rarity(Rarity.EPIC)));
public static final BlockItem END_GATEWAY_BLOCK_ITEM = Registry.register(Registries.ITEM, id("end_gateway"), new BlockItem(Blocks.END_GATEWAY, new FabricItemSettings().rarity(Rarity.EPIC)));
public static final BlockItem BUBBLE_COLUMN_BLOCK_ITEM = Registry.register(Registries.ITEM, id("bubble_column"), new BlockItem(Blocks.BUBBLE_COLUMN, new FabricItemSettings().rarity(Rarity.EPIC)));
//Packet Identifiers
public static final Identifier MOD_INSTALLED_PACKET = id("mod_installed");

@Override
public void onInitialize() {
ItemGroupEvents.modifyEntriesEvent(ItemGroups.OPERATOR).register(content -> {
for (PistonType type : PistonType.values()) {
ItemStack stack = new ItemStack(VisibleBarriersCommon.MOVING_PISTON_BLOCK_ITEM);
NbtCompound nbtCompound = new NbtCompound();
nbtCompound.putString(PistonExtensionBlock.TYPE.getName(), String.valueOf(type));
stack.setSubNbt("BlockStateTag", nbtCompound);
content.add(stack);
content.add(makeVariant(VisibleBarriersCommon.MOVING_PISTON_BLOCK_ITEM, PistonExtensionBlock.TYPE.getName(), String.valueOf(type)));
}
for (BlockItem item : List.of(AIR_BLOCK_ITEM, CAVE_AIR_BLOCK_ITEM, VOID_AIR_BLOCK_ITEM, END_PORTAL_BLOCK_ITEM, END_GATEWAY_BLOCK_ITEM)) {
content.add(new ItemStack(item));
}
content.add(makeVariant(VisibleBarriersCommon.BUBBLE_COLUMN_BLOCK_ITEM, "drag", "true"));
content.add(makeVariant(VisibleBarriersCommon.BUBBLE_COLUMN_BLOCK_ITEM, "drag", "false"));
});
ServerPlayNetworking.registerGlobalReceiver(MOD_INSTALLED_PACKET, (server, player, handler, buf, responseSender) -> {
LOGGER.info("{} has mod Visible Barriers installed.", player.getEntityName());
ServerPlayNetworking.send(player, MOD_INSTALLED_PACKET, buf);
});
}

private static ItemStack makeVariant(Item item, String nbtKey, String nbtValue) {
NbtCompound comp = new NbtCompound();
comp.putString(nbtKey, nbtValue);
ItemStack stack = new ItemStack(item);
stack.setSubNbt("BlockStateTag", comp);
return stack;
}

public static Identifier id(String ... path) {
return new Identifier(MOD_ID, String.join(".", path));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package xyz.amymialee.visiblebarriers.mixin;

import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
import net.minecraft.block.BlockState;
import net.minecraft.block.BubbleColumnBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xyz.amymialee.visiblebarriers.VisibleBarriers;
import xyz.amymialee.visiblebarriers.common.VisibleBarriersCommon;
import xyz.amymialee.visiblebarriers.mixin.boxing.BlockMixin;

@Mixin(BubbleColumnBlock.class)
public abstract class BubbleColumnBlockMixin extends BlockMixin implements BlockPickInteractionAware {
@Override
public void visibleBarriers$getPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable<BlockState> cir) {
ItemStack stack = ctx.getStack();
NbtCompound tag = stack.getSubNbt("BlockStateTag");
boolean drag = true;
if (tag != null) {
drag = tag.getString("drag").equals("true");
}

cir.setReturnValue(this.getDefaultState().with(BubbleColumnBlock.DRAG, drag));
}

@Override
public ItemStack getPickedStack(BlockState state, BlockView view, BlockPos pos, PlayerEntity player, HitResult result) {
ItemStack stack = new ItemStack(VisibleBarriersCommon.BUBBLE_COLUMN_BLOCK_ITEM);
NbtCompound nbtCompound = new NbtCompound();
nbtCompound.putString("drag", String.valueOf(state.get(BubbleColumnBlock.DRAG)));
stack.setSubNbt("BlockStateTag", nbtCompound);
return stack;
}

@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void visibleBarriers$visibleOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (VisibleBarriers.isVisibilityEnabled() || VisibleBarriers.areBubbleColumnsEnabled() || context == ShapeContext.absent()) {
cir.setReturnValue(VoxelShapes.fullCube());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package xyz.amymialee.visiblebarriers.mixin.client;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.Blocks;
import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xyz.amymialee.visiblebarriers.VisibleConfig;
import xyz.amymialee.visiblebarriers.VisibleBarriers;
Expand All @@ -28,6 +30,8 @@ public abstract class AbstractBlockStateMixin {
cir.setReturnValue(BlockRenderType.MODEL);
} else if (this.getBlock() == Blocks.LIGHT && VisibleBarriers.areLightsEnabled()) {
cir.setReturnValue(BlockRenderType.MODEL);
} else if (this.getBlock() == Blocks.BUBBLE_COLUMN && VisibleBarriers.areBubbleColumnsEnabled()) {
cir.setReturnValue(BlockRenderType.MODEL);
} else if (this.getBlock() == Blocks.STRUCTURE_VOID && VisibleBarriers.areStructureVoidsEnabled()) {
cir.setReturnValue(BlockRenderType.MODEL);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package xyz.amymialee.visiblebarriers.mixin.client;

import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BubbleColumnBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xyz.amymialee.visiblebarriers.mixin.boxing.BlockMixin;

@Mixin(BubbleColumnBlock.class)
public abstract class ClientBubbleColumnBlockMixin extends BlockMixin implements BlockPickInteractionAware {
@Override
public void visibleBarriers$isSideInvisible(BlockState state, BlockState stateFrom, Direction direction, CallbackInfoReturnable<Boolean> cir) {
if (stateFrom.isOf((Block) (Object) this)) {
cir.setReturnValue(true);
}
}

@Override
public void visibleBarriers$isTranslucent(BlockState state, BlockView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.amymialee.visiblebarriers.mixin.client;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ParticleManager.class)
public class ParticleManagerMixin {
@Inject(method = "addBlockBreakingParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getOutlineShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/shape/VoxelShape;", shift = At.Shift.BEFORE), cancellable = true)
private void visibleBarriers$removeWaterBreakParticles(BlockPos pos, Direction direction, CallbackInfo ci, @Local BlockState blockState) {
if (blockState.getBlock() instanceof FluidBlock) {
ci.cancel();
}
}

}
10 changes: 10 additions & 0 deletions src/main/resources/assets/minecraft/blockstates/bubble_column.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"variants": {
"drag=true": {
"model": "visiblebarriers:block/bubble_column_down"
},
"drag=false": {
"model": "visiblebarriers:block/bubble_column_up"
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/visiblebarriers/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"key.visiblebarriers.barriers" : "Show Barriers",
"key.visiblebarriers.lights" : "Show Lights",
"key.visiblebarriers.structurevoids" : "Show Structure Voids",
"key.visiblebarriers.bubblecolumns" : "Show Bubble Columns",
"key.visiblebarriers.fullbright" : "Toggle Fullbright",
"key.visiblebarriers.time" : "Toggle Forced Time",
"key.visiblebarriers.zoom" : "Zoom",
Expand All @@ -22,6 +23,7 @@
"visiblebarriers.feedback.barriers" : "Barriers",
"visiblebarriers.feedback.lights" : "Lights",
"visiblebarriers.feedback.structurevoids" : "Structure Voids",
"visiblebarriers.feedback.bubblecolumns" : "Bubble Columns",
"visiblebarriers.feedback.zoom" : "Zoom: %s %%",

"visiblebarriers.command.reload" : "[Visible Barriers] Reloaded config",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/cube_bottom_top",
"textures": {
"bottom": "visiblebarriers:block/bubble_column_top",
"side": "visiblebarriers:block/bubble_column_down",
"top": "visiblebarriers:block/bubble_column_bottom"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/cube_bottom_top",
"textures": {
"bottom": "visiblebarriers:block/bubble_column_bottom",
"side": "visiblebarriers:block/bubble_column_up",
"top": "visiblebarriers:block/bubble_column_top"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "visiblebarriers:block/bubble_column_up",
"overrides": [
{ "predicate": { "drag": 1 }, "model": "visiblebarriers:item/bubble_column_down" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "visiblebarriers:block/bubble_column_down"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main/resources/visiblebarriers.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AirBlockMixin",
"BubbleColumnBlockMixin",
"EntityTypeMixin",
"MarkerEntityMixin",
"PistonExtensionBlockMixin",
Expand All @@ -15,18 +16,20 @@
"client": [
"boxing.EntityRendererMixin",
"client.AbstractBlockStateMixin",
"client.ClientBubbleColumnBlockMixin",
"client.ClientPistonExtensionBlockMixin",
"client.ClientPlayerInteractionManagerMixin",
"client.ClientWorldMixin",
"client.ClientWorldMixin$ClientWorldPropertiesMixin",
"client.DisplayContextMixin",
"client.EmptyEntityRendererMixin",
"client.EntityMixin",
"client.GameRendererMixin",
"client.ItemStackMixin",
"client.LightBlockMixin",
"client.LightmapTextureManagerMixin",
"client.MouseMixin",
"client.DisplayContextMixin"
"client.ParticleManagerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down