Skip to content
Open
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
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
.gradle/
build/
out/
classes/

# eclipse

*.launch

# idea

Expand All @@ -11,7 +16,18 @@ out/
*.ipr
*.iws

# vscode

.settings/
.vscode/
bin/
.classpath
.project

# macos

*.DS_Store

# fabric

run/
classes/
38 changes: 27 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
plugins {
id 'fabric-loom' version "0.5-SNAPSHOT"
id 'fabric-loom' version "0.9.+"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = "CustomSelectionBox"
version = "5.0.2"
version = "5.1.0"

minecraft {
}

repositories {
maven { url "https://dl.bintray.com/shedaniel/legacy-yarn-updated" }
}

processResources {
filesMatching('fabric.mod.json') {
expand 'version': project.version
}
inputs.property "version", project.version
}

repositories {
maven {
url 'https://maven.terraformersmc.com/releases/'
}
}

dependencies {
minecraft "com.mojang:minecraft:1.16.2"
mappings "me.shedaniel:legacy-yarn:1.16.2+build.9+legacy.20w09a+build.8:v2"
modCompile "net.fabricmc:fabric-loader:0.9.2+build.206"
minecraft "com.mojang:minecraft:1.17.1"
mappings "net.fabricmc:yarn:1.17.1+build.43:v2"
modImplementation "net.fabricmc:fabric-loader:0.11.6"

// Fabric api
// Make a collection of all api modules we wish to use
Set<String> apiModules = [
"fabric-command-api-v1"
]

// Add each module as a dependency
apiModules.forEach {
include(modImplementation(fabricApi.module(it, "0.38.2+1.17")))
}

// Mod Menu
modCompileOnly "com.terraformersmc:modmenu:2.0.5"
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx4G
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginManagement {
jcenter()
maven {
name = 'Fabric'
url = 'http://maven.fabricmc.net/'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
Expand Down
147 changes: 132 additions & 15 deletions src/main/java/me/shedaniel/csb/CSB.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package me.shedaniel.csb;

import me.shedaniel.csb.api.CSBRenderer;
import me.shedaniel.csb.gui.CSBSettingsScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.block.*;
import net.minecraft.block.enums.BedPart;
import net.minecraft.block.enums.PistonType;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;

public class CSB implements ClientModInitializer {

public static final List<CSBRenderer> RENDERERS = new ArrayList<>();

public static void openSettingsGUI(MinecraftClient client, Screen parent) {
client.openScreen(new CSBSettingsScreen(parent));
client.setScreen(new CSBSettingsScreen(parent));
}

@Override
public void onInitializeClient() {
RENDERERS.clear();
RENDERERS.addAll(FabricLoader.getInstance().getEntrypoints("csb_renderers", CSBRenderer.class));
RENDERERS.sort(Comparator.comparingDouble(CSBRenderer::getPriority));
if (RENDERERS.isEmpty()) {
throw new IllegalStateException("No default CSB renderers!");
}
ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("csbconfig").executes(context -> {
openSettingsGUI(context.getSource().getClient(), null);
return 1;
}));
}

public static int HSBtoRGB(float hue, float saturation, float brightness) {
Expand Down Expand Up @@ -76,4 +79,118 @@ public static int HSBtoRGB(float hue, float saturation, float brightness) {

return -16777216 | r << 16 | g << 8 | b;
}

public static void drawBox(Tessellator tessellator, BufferBuilder bufferBuilder, double x1, double y1, double z1, double x2, double y2, double z2, float red, float green, float blue, float alpha) {
// Up
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
tessellator.draw();

// Down
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next();
tessellator.draw();

// North
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
tessellator.draw();

// South
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next();
tessellator.draw();

// West
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next();
tessellator.draw();

// East
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next();
bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next();
tessellator.draw();
}

public static VoxelShape adjustShapeByLinkedBlocks(ClientWorld world, BlockState blockState, BlockPos blockPos, VoxelShape shape) {
try {
if (blockState.getBlock() instanceof ChestBlock) {
// Chests
Block block = blockState.getBlock();
Direction facing = ChestBlock.getFacing(blockState);
BlockState anotherChestState = world.getBlockState(blockPos.offset(facing, 1));
if (anotherChestState.getBlock() == block)
if (blockPos.offset(facing, 1).offset(ChestBlock.getFacing(anotherChestState)).equals(blockPos))
return VoxelShapes.union(shape, anotherChestState.getOutlineShape(world, blockPos).offset(facing.getOffsetX(), facing.getOffsetY(), facing.getOffsetZ()));
} else if (blockState.getBlock() instanceof DoorBlock) {
// Doors
Block block = blockState.getBlock();
if (world.getBlockState(blockPos.up(1)).getBlock() == block) {
BlockState otherState = world.getBlockState(blockPos.up(1));
if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE))) {
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, 1, 0));
}
}
if (world.getBlockState(blockPos.down(1)).getBlock() == block) {
BlockState otherState = world.getBlockState(blockPos.down(1));
if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE)))
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, -1, 0));
}
} else if (blockState.getBlock() instanceof BedBlock) {
// Beds
Block block = blockState.getBlock();
Direction direction = blockState.get(HorizontalFacingBlock.FACING);
BlockState otherState = world.getBlockState(blockPos.offset(direction));
if (blockState.get(BedBlock.PART).equals(BedPart.FOOT) && otherState.getBlock() == block) {
if (otherState.get(BedBlock.PART).equals(BedPart.HEAD))
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ()));
}
otherState = world.getBlockState(blockPos.offset(direction.getOpposite()));
direction = direction.getOpposite();
if (blockState.get(BedBlock.PART).equals(BedPart.HEAD) && otherState.getBlock() == block) {
if (otherState.get(BedBlock.PART).equals(BedPart.FOOT))
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ()));
}
} else if (blockState.getBlock() instanceof PistonBlock && blockState.get(PistonBlock.EXTENDED)) {
// Piston Base
Block block = blockState.getBlock();
Direction direction = blockState.get(FacingBlock.FACING);
BlockState otherState = world.getBlockState(blockPos.offset(direction));
if (otherState.get(PistonHeadBlock.TYPE).equals(block == Blocks.PISTON ? PistonType.DEFAULT : PistonType.STICKY) && direction.equals(otherState.get(FacingBlock.FACING)))
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ()));
} else if (blockState.getBlock() instanceof PistonHeadBlock) {
// Piston Arm
Direction direction = blockState.get(FacingBlock.FACING);
BlockState otherState = world.getBlockState(blockPos.offset(direction.getOpposite()));
if (otherState.getBlock() instanceof PistonBlock && direction == otherState.get(FacingBlock.FACING) && otherState.get(PistonBlock.EXTENDED))
return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos.offset(direction.getOpposite())).offset(direction.getOpposite().getOffsetX(), direction.getOpposite().getOffsetY(), direction.getOpposite().getOffsetZ()));
}
} catch (Throwable ignored) {
}
return shape;
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/shedaniel/csb/CSBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CSBConfig implements ClientModInitializer {
public static boolean disableDepthBuffer;
public static boolean adjustBoundingBoxByLinkedBlocks;
public static boolean rainbow;
private static File configFile = new File(FabricLoader.getInstance().getGameDirectory(), "config" + File.separator + "CSB" + File.separator + "config.json");
private static File configFile = new File(FabricLoader.getInstance().getGameDir().toFile(), "config" + File.separator + "CSB" + File.separator + "config.json");

private static void loadConfig() throws IOException {
configFile.getParentFile().mkdirs();
Expand Down
Loading