Skip to content

Commit

Permalink
Updated carpet acording to original branch, xcom's commit says "Fixed…
Browse files Browse the repository at this point in the history
… loadChunk and renamed" and also "Merge remote-tracking branch 'origin/staging' into staging"
  • Loading branch information
Dioswilson committed Jan 23, 2022
1 parent 8654230 commit 4e4abab
Show file tree
Hide file tree
Showing 15 changed files with 994 additions and 235 deletions.
3 changes: 2 additions & 1 deletion carpetmodSrc/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class CarpetServer // static for now - easier to handle all around the co
public static ToggleableChannelHandler rsmmChannel;
public static ToggleableChannelHandler wecuiChannel;
public static boolean playerInventoryStacking = false;
public static int limitITTCounter;

private static CarpetClientServer CCServer;

Expand Down Expand Up @@ -129,7 +130,7 @@ public static void playerDisconnected(EntityPlayerMP player)
pluginChannels.onPlayerDisconnected(player);
LoggerRegistry.playerDisconnected(player);
}

public static Random setRandomSeed(int p_72843_1_, int p_72843_2_, int p_72843_3_)
{
long i = (long)p_72843_1_ * 341873128712L + (long)p_72843_2_ * 132897987541L + CCServer.getMinecraftServer().worlds[0].getWorldInfo().getSeed() + (long)p_72843_3_;
Expand Down
21 changes: 16 additions & 5 deletions carpetmodSrc/carpet/CarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class CarpetSettings {
public static boolean locked = false;

public static final String carpetVersion = "v21_12_30";
public static final String carpetVersion = "v21_12_26";
public static final String minecraftVersion = "1.12.2";
public static final String mcpMappings = "39-1.12";

Expand Down Expand Up @@ -86,10 +86,15 @@ public class CarpetSettings {
})
public static boolean commandBlockInfo = true;

@Rule(desc = "Enables /loadchunk command", category = COMMANDS, extra = {
"Loads a chunk remotely"
@Rule(desc = "Enables /chunk command", category = COMMANDS, extra = {
"chunk info command"
})
public static boolean commandLoadChunk = true;
public static boolean commandChunk = true;

@Rule(desc = "Enables /loadedChunks command", category = COMMANDS, extra = {
"Get information of the loaded chunks hashmap"
})
public static boolean commandLoadedChunks = true;

@Rule(desc = "Enables /entityinfo command", category = COMMANDS, extra = {
"Also enables yellow carpet placement action if 'carpets' rule is turned on as well"
Expand Down Expand Up @@ -505,6 +510,12 @@ public static enum WhereToChunkSavestate {
* Rules in this category should end with the "Fix" suffix
*/

@Rule(desc = "A limiter for updates happening on the main thread to prevent crashes on instant tile tick.", category = FIX, options = {"0", "1000000", "10000000"})
public static int limitITTupdates = 0;

@Rule(desc = "Fixes the async packet bugs related to asynch observer updates.", category = FIX)
public static boolean asyncPacketUpdatesFix;

@Rule(desc = "Fixes the pearl bugs removing them when players relog, similar fix to mc1.15.", category = FIX)
public static boolean fixedPearlBugs;

Expand Down Expand Up @@ -1108,7 +1119,7 @@ private static boolean validateDoorCheckOptimization(boolean value) {
@Rule(desc = "enables /sb to display player's stats as scoreboard with a total entry", category = {EXPERIMENTAL, SURVIVAL, BULLET})
public static boolean scoreboardStats;

@Rule(desc = "Fixes block states in F3 debug mode not updating for hoppers, droppers and dispensers", category = {FIX, EXPERIMENTAL, BULLET})
@Rule(desc = "Fixes block states in F3 debug mode not updating for hoppers, droppers and dispensers.", category = {FIX, EXPERIMENTAL, BULLET})
public static boolean blockStateSyncing;

// ===== API ===== //
Expand Down
8 changes: 6 additions & 2 deletions carpetmodSrc/carpet/commands/CarpetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void register(CommandHandler handler) {
handler.registerCommand(new CommandAutosave());
handler.registerCommand(new CommandBlockInfo());
handler.registerCommand(new CommandCarpet());
handler.registerCommand(new CommandChunk());
handler.registerCommand(new CommandCounter());
handler.registerCommand(new CommandDebugCarpet());
handler.registerCommand(new CommandDebuglogger());
Expand All @@ -25,7 +26,7 @@ public static void register(CommandHandler handler) {
handler.registerCommand(new CommandLagSpike());
handler.registerCommand(new CommandLazyChunkBehavior());
handler.registerCommand(new CommandLight());
handler.registerCommand(new CommandLoadChunk());
handler.registerCommand(new CommandLoadedChunks());
handler.registerCommand(new CommandLog());
handler.registerCommand(new CommandPerimeter());
handler.registerCommand(new CommandPing());
Expand All @@ -47,9 +48,12 @@ public static void register(CommandHandler handler) {
handler.registerCommand(new CommandTNT());
handler.registerCommand(new CommandUnload());
handler.registerCommand(new CommandUnload13());
//handler.registerCommand(new CommandUpdateCarpet());
handler.registerCommand(new CommandUpdateCarpet());
handler.registerCommand(new CommandVillage());
handler.registerCommand(new CommandWaypoint());
handler.registerCommand(new CommandChunk());
handler.registerCommand(new CommandLoadedChunks());
handler.registerCommand(new CommandZetBlock());

// ----- RSMM Start ----- //
handler.registerCommand(new MeterCommand(CarpetServer.rsmmServer));
Expand Down
4 changes: 4 additions & 0 deletions carpetmodSrc/carpet/commands/CommandCarpetBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import carpet.utils.Messenger;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.NumberInvalidException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.ITextComponent;
Expand Down Expand Up @@ -56,5 +57,8 @@ public boolean command_enabled(String command_name, ICommandSender sender)
return true;
}

protected int parseChunkPosition(String arg, int base) throws NumberInvalidException {
return arg.equals("~") ? base >> 4 : parseInt(arg);
}

}
110 changes: 110 additions & 0 deletions carpetmodSrc/carpet/commands/CommandChunk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package carpet.commands;

import it.unimi.dsi.fastutil.HashCommon;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

public class CommandChunk extends CommandCarpetBase
{
/**
* Gets the name of the command
*/

public String getUsage(ICommandSender sender)
{
return "Usage: chunk <load | info | unload> <X> <Z>";
}

public String getName()
{
return "chunk";
}

protected World world;
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (!command_enabled("commandChunk", sender)) return;

if (args.length != 3) {
throw new WrongUsageException(getUsage(sender));
}

world = sender.getEntityWorld();
try {
int chunkX = parseChunkPosition(args[1], sender.getPosition().getX());
int chunkZ = parseChunkPosition(args[2], sender.getPosition().getZ());

switch (args[0]){
case "load":
world.getChunk(chunkX, chunkZ);
sender.sendMessage(new TextComponentString("Chunk " + chunkX + ", " + chunkZ + " loaded"));
return;
case "unload":
unload(sender, chunkX, chunkZ);
return;
case "info":
default:
info(sender, chunkX, chunkZ);

}
}catch (Exception e){
throw new WrongUsageException(getUsage(sender));
}
}

protected void info(ICommandSender sender, int x, int z) throws NoSuchFieldException, IllegalAccessException {
if(!world.isChunkLoaded(x, z, false)) {
sender.sendMessage(new TextComponentString(("Chunk is not loaded")));
}

long i = ChunkPos.asLong(x, z);
ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
int mask = CommandLoadedChunks.getMask((Long2ObjectOpenHashMap<Chunk>) provider.loadedChunks);
long key = HashCommon.mix(i) & mask;
sender.sendMessage(new TextComponentString(("Chunk ideal key is " + key)));
if (world.isSpawnChunk(x, z))
sender.sendMessage(new TextComponentString(("Spawn Chunk")));
}

protected void unload(ICommandSender sender, int x, int z){
if(!world.isChunkLoaded(x, z, false)) {
sender.sendMessage(new TextComponentString(("Chunk is not loaded")));
return;
}
Chunk chunk = world.getChunk(x, z);
ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
provider.queueUnload(chunk);
sender.sendMessage(new TextComponentString(("Chunk is queue to unload")));
}

public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
int chunkX = sender.getPosition().getX() >> 4;
int chunkZ = sender.getPosition().getZ() >> 4;

if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, "info", "load", "unload");
} else if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkX), "~");
} else if (args.length == 3) {
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkZ), "~");
} else {
return Collections.emptyList();
}
}
}
65 changes: 0 additions & 65 deletions carpetmodSrc/carpet/commands/CommandLoadChunk.java

This file was deleted.

Loading

0 comments on commit 4e4abab

Please sign in to comment.