-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More version-agnostic helpers Distributed room scanning over multiple ticks On a long-lived server with many registered doors, we were encountering crashes due to exceeding the 60 second tick limit. Instead of trying to calculate all rooms in a single tick, we now detect individual rooms per tick and utilize PendingTownRooms to collect and register them once they've all been detected. Updating RoomRecipes to debug some scanning problems Added debug mode for debugging room scans Switched debug from config to command Remove debug configs
- Loading branch information
Showing
19 changed files
with
716 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/ca/bradj/questown/commands/DebugCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ca.bradj.questown.commands; | ||
|
||
import ca.bradj.questown.town.TownFlagBlockEntity; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
|
||
public class DebugCommand { | ||
public static void register(CommandDispatcher<CommandSourceStack> p_137808_) { | ||
p_137808_.register(Commands.literal("qtdebug") | ||
.requires((p_137812_) -> { | ||
return p_137812_.hasPermission(2); | ||
}) | ||
.then(Commands.argument("pos", BlockPosArgument.blockPos()) | ||
.executes(css -> { | ||
return startDebug(css.getSource(), BlockPosArgument.getLoadedBlockPos(css, "pos")); | ||
}))); | ||
} | ||
|
||
private static int startDebug( | ||
CommandSourceStack source, | ||
BlockPos target | ||
) { | ||
BlockEntity e = source.getLevel().getBlockEntity(target); | ||
if (!(e instanceof TownFlagBlockEntity tfbe)) { | ||
// TODO: Better error handling? | ||
return -1; | ||
} | ||
|
||
tfbe.toggleDebugMode(); | ||
return 0; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/ca/bradj/questown/commands/DebugDoorsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ca.bradj.questown.commands; | ||
|
||
import ca.bradj.questown.blocks.TownFlagBlock; | ||
import ca.bradj.questown.core.init.items.ItemsInit; | ||
import ca.bradj.questown.town.TownFlagBlockEntity; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
|
||
public class DebugDoorsCommand { | ||
public static void register(CommandDispatcher<CommandSourceStack> p_137808_) { | ||
p_137808_.register(Commands.literal("qtdebugdoors") | ||
.requires((p_137812_) -> { | ||
return p_137812_.hasPermission(2); | ||
}) | ||
.then(Commands.argument("pos", BlockPosArgument.blockPos()) | ||
.executes(css -> { | ||
return giveDebug(css.getSource(), BlockPosArgument.getLoadedBlockPos(css, "pos")); | ||
}))); | ||
} | ||
|
||
private static int giveDebug( | ||
CommandSourceStack source, | ||
BlockPos target | ||
) { | ||
BlockEntity e = source.getLevel().getBlockEntity(target); | ||
if (!(e instanceof TownFlagBlockEntity tfbe)) { | ||
// TODO: Better error handling? | ||
return -1; | ||
} | ||
|
||
ItemStack debugItem = ItemsInit.TOWN_DOOR_TESTER.get() | ||
.getDefaultInstance(); | ||
TownFlagBlock.StoreParentOnNBT( | ||
debugItem, | ||
target | ||
); | ||
try { | ||
source.getPlayerOrException().getInventory().add(debugItem); | ||
} catch (CommandSyntaxException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/ca/bradj/questown/items/TownDoorTestItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ca.bradj.questown.items; | ||
|
||
import ca.bradj.questown.Questown; | ||
import ca.bradj.questown.blocks.TownFlagBlock; | ||
import ca.bradj.questown.town.TownFlagBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.DoorBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class TownDoorTestItem extends Item { | ||
public static final String ITEM_ID = "town_door_tester"; | ||
|
||
public TownDoorTestItem() { | ||
super(Questown.DEFAULT_ITEM_PROPS); | ||
} | ||
|
||
@Override | ||
public InteractionResult useOn(net.minecraft.world.item.context.UseOnContext ctx) { | ||
return startDebug(ctx); | ||
} | ||
|
||
@NotNull | ||
private static InteractionResult startDebug(net.minecraft.world.item.context.UseOnContext ctx) { | ||
if (ctx.getLevel() | ||
.isClientSide()) { | ||
return InteractionResult.PASS; | ||
} | ||
TownFlagBlockEntity parent = TownFlagBlock.GetParentFromNBT((ServerLevel) ctx.getLevel(), ctx.getItemInHand()); | ||
BlockPos clickedPos = ctx.getClickedPos(); | ||
BlockState bs = parent.getServerLevel() | ||
.getBlockState(clickedPos); | ||
if (bs.getBlock() instanceof DoorBlock) { | ||
if (DoubleBlockHalf.UPPER.equals(bs.getValue(DoorBlock.HALF))) { | ||
clickedPos = clickedPos.below(); | ||
} | ||
} else { | ||
bs = parent.getServerLevel() | ||
.getBlockState(clickedPos.above()); | ||
if (bs.getBlock() instanceof DoorBlock) { | ||
clickedPos = clickedPos.above(); | ||
} | ||
} | ||
parent.startDebugTask(parent.getRoomHandle() | ||
.getDebugTaskForDoor(clickedPos)); | ||
return InteractionResult.CONSUME; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.