Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
FxMorin committed Apr 28, 2021
1 parent f44a767 commit 0f6ae95
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx1G
carpet_core_version=1.4.17+v201111

# Mod Properties
mod_version = 1.0.3
mod_version = 1.0.4
maven_group = weirdaddons
archives_base_name = weirdaddons

Expand Down
68 changes: 68 additions & 0 deletions src/main/java/weirdaddons/WeirdAddonsCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package weirdaddons;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.minecraft.command.argument.ColumnPosArgumentType;
import net.minecraft.server.command.ServerCommandSource;

import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;

public class WeirdAddonsCommands {

public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
// This is totally not sketch or anything. Totally didn't just throw this together within a couple minutes...
dispatcher.register(literal("weird").
then(literal("chunk").
then(literal("set").
then(argument("daChunk", ColumnPosArgumentType.columnPos()).
executes((c)-> {
WeirdAddonsSettings.chunkPos = ColumnPosArgumentType.getColumnPos(c, "daChunk");
WeirdAddonsUtils.sendToPlayer("Targetted chunk set to: "+WeirdAddonsSettings.chunkPos);
return 1;
}))).
then(literal("start").
executes((c)-> {
if (!WeirdAddonsServer.mc.isInSingleplayer()) {
WeirdAddonsUtils.sendToPlayer("Currently this feature is only available in singleplayer cause im lazy :)");
} else if (WeirdAddonsSettings.chunkPos == null) {
WeirdAddonsUtils.sendToPlayer("A chunk must be specified before this can be enabled!");
} else if (WeirdAddonsSettings.isDisplayingChunk) {
WeirdAddonsUtils.sendToPlayer("Chunk has already started!");
} else {
WeirdAddonsSettings.isDisplayingChunk = true;
WeirdAddonsUtils.sendToPlayer("Chunk has started!");
}
return 1;
})
).
then(literal("stop").
executes((c)-> {
if (WeirdAddonsSettings.isDisplayingChunk) {
WeirdAddonsSettings.isDisplayingChunk = false;
WeirdAddonsUtils.sendToPlayer("Chunk has stopped!");
} else {
WeirdAddonsUtils.sendToPlayer("Chunk is not running!");
}
return 1;
})
).
then(literal("radius").
then(argument("radius", IntegerArgumentType.integer(0)).
executes((c)-> {
WeirdAddonsSettings.chunkRadius = IntegerArgumentType.getInteger(c, "radius");
WeirdAddonsUtils.sendToPlayer("Chunk Radius has been set to: "+WeirdAddonsSettings.chunkRadius);
return 1;
}))
)
).
then(literal("control").
executes((c)-> {
WeirdAddonsUtils.sendToPlayer("Not implemented yet...");
return 1;
})
));

}
}
25 changes: 23 additions & 2 deletions src/main/java/weirdaddons/WeirdAddonsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import carpet.CarpetExtension;
import carpet.CarpetServer;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;

import java.util.Objects;

public class WeirdAddonsServer implements CarpetExtension, ModInitializer
{
Expand All @@ -17,8 +26,20 @@ public static void noop() {}
}

@Override
public void onGameStarted() {
CarpetServer.settingsManager.parseSettingsClass(WeirdAddonsSettings.class);
public void onGameStarted() { CarpetServer.settingsManager.parseSettingsClass(WeirdAddonsSettings.class); }

@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher)
{
WeirdAddonsCommands.register(dispatcher);
}

@Override
public void onTick(MinecraftServer server) {
//I really didn't care when I was implementing this xD
if (WeirdAddonsSettings.isDisplayingChunk && WeirdAddonsSettings.lampChunkStatus <= 0 && mc.world != null) { //Don't run both at the same time!
WeirdAddonsUtils.sendToPlayer(WeirdAddonsUtils.DisplayChunks(server.getWorld(mc.player.world.getRegistryKey()), new ChunkPos(WeirdAddonsSettings.chunkPos.x, WeirdAddonsSettings.chunkPos.z), WeirdAddonsSettings.chunkRadius));
}
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/weirdaddons/WeirdAddonsSettings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package weirdaddons;

import carpet.settings.Rule;
import net.minecraft.util.math.ColumnPos;

import static carpet.settings.RuleCategory.CREATIVE;
import static carpet.settings.RuleCategory.BUGFIX;
Expand All @@ -9,6 +10,10 @@

public class WeirdAddonsSettings
{
public static boolean isDisplayingChunk = false;
public static ColumnPos chunkPos;
public static int chunkRadius = 5;

private final static String WEIRD = "weird";

@Rule(
Expand Down Expand Up @@ -84,4 +89,10 @@ public class WeirdAddonsSettings
)
public static String lampChunkDisplay = "chat";

@Rule(
desc = "COLOR!",
category = {CLIENT,WEIRD}
)
public static boolean colorify = false;

}
9 changes: 4 additions & 5 deletions src/main/java/weirdaddons/WeirdAddonsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ public static void largeChatHud(boolean large) {
}


public static String DisplayChunks(World world, BlockPos pos, int radius){
public static String DisplayChunks(World world, ChunkPos pos, int radius){
ClientPlayerEntity player = WeirdAddonsServer.mc.player;
ChunkPos cpos = new ChunkPos(pos);
ChunkManager chunkManager = world.getChunkManager();
StringBuilder result = new StringBuilder();
for (int x = cpos.x-radius; x <= cpos.x+radius; x++) {
for (int z = cpos.z-radius; z <= cpos.z+radius; z++) {
for (int x = pos.x-radius; x <= pos.x+radius; x++) {
for (int z = pos.z-radius; z <= pos.z+radius; z++) {
char icon = '█';
WorldChunk chunk = chunkManager.getWorldChunk(x, z, false);
if (x == cpos.x && z == cpos.z) {
if (x == pos.x && z == pos.z) {
icon = '◎';
}
if (chunk != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/weirdaddons/mixins/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/weirdaddons/mixins/RedstoneLampBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RedstoneLampBlockMixin(Settings settings) {
))
public boolean neighborSetState(World world, BlockPos pos, BlockState state, int flags) {
if (WeirdAddonsSettings.lampChunkStatus > 0 && !state.get(LIT) && world.getBlockState(pos.down()).isOf(Blocks.BARRIER)) {
WeirdAddonsUtils.sendToPlayer(WeirdAddonsUtils.DisplayChunks(world, pos, WeirdAddonsSettings.lampChunkStatus));
WeirdAddonsUtils.sendToPlayer(WeirdAddonsUtils.DisplayChunks(world, new ChunkPos(pos), WeirdAddonsSettings.lampChunkStatus));
}
return world.setBlockState(pos, state, flags);
}
Expand All @@ -50,7 +50,7 @@ public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Ran
if (state.get(LIT) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(LIT), 2);
if (WeirdAddonsSettings.lampChunkStatus > 0 && world.getBlockState(pos.down()).isOf(Blocks.BARRIER)) {
WeirdAddonsUtils.sendToPlayer(WeirdAddonsUtils.DisplayChunks(world, pos, WeirdAddonsSettings.lampChunkStatus));
WeirdAddonsUtils.sendToPlayer(WeirdAddonsUtils.DisplayChunks(world, new ChunkPos(pos), WeirdAddonsSettings.lampChunkStatus));
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/weirdaddons/mixins/ScaffoldingBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ class ScaffoldingBlockMixin extends Block{

@Shadow
public static final BooleanProperty WATERLOGGED;
@Shadow
public static final IntProperty DISTANCE;
@Shadow
public static final BooleanProperty BOTTOM;

static {
WATERLOGGED = Properties.WATERLOGGED;
DISTANCE = Properties.DISTANCE_0_7;
BOTTOM = Properties.BOTTOM;
}

public ScaffoldingBlockMixin(Settings settings) {
Expand All @@ -44,12 +38,13 @@ public ScaffoldingBlockMixin(Settings settings) {
target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"
))
public boolean ScaffoldingBreaking(ServerWorld serverWorld, BlockPos pos, boolean drop) {
if (WeirdAddonsSettings.scaffoldingBreaking.equals("break")){
return serverWorld.breakBlock(pos, true);
if (WeirdAddonsSettings.scaffoldingBreaking.equals("float")) {
return true;
} else if (WeirdAddonsSettings.scaffoldingBreaking.equals("gravity")) {
return serverWorld.spawnEntity(new FallingBlockEntity(serverWorld, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D,serverWorld.getBlockState(pos).with(WATERLOGGED, false)));
} else {
return serverWorld.breakBlock(pos, true);
}
return false;
}

@Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true)
Expand Down

0 comments on commit 0f6ae95

Please sign in to comment.