added add_chunk_ticket

This commit is contained in:
gnembon committed 2020-05-17 23:52:59 -03:00
1 parent 74c62e5a13
commit 06ede1fbc0
4 files changed
+38

No files matched your search

+7
View File
@@ -712,3 +712,10 @@ It returns a `map` with a report indicating how many chunks were affected, and h
* `layer_count_<status>`: number of chunks for which a `<status>` generation step has been performed
* `layer_time_<status>`: cumulative time for all chunks spent on generating `<status>` step
### add_chunk_ticket(pos, type, radius)
Adds a chunk ticket at a position, which makes the game to keep the designated area centered around
`pos` with radius of `radius` loaded for a predefined amount of ticks, defined by `type`. Allowed types
are `portal`: 300 ticks, `teleport`: 5 ticks, and `unknown`: 1 tick. Radius can be from 1 to 32 ticks.
This function is tentative - will likely change when chunk ticket API is properly fleshed out.
@@ -1,4 +1,5 @@
air
add_chunk_ticket
biome
blast_resistance
block
@@ -56,6 +56,7 @@
blocks_movement block_sound material map_colour property block_properties block_data poi set_poi
place_item set_biome biome loaded_status generation_status inhabited_time spawn_potential chunk_tickets
structure_eligibility structures structure_references set_structure reset_chunk reload_chunk
add_chunk_ticket
scoreboard scoreboard_add scoreboard_remove scoreboard_display
@@ -88,6 +88,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicket;
import net.minecraft.server.world.ChunkTicketType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
@@ -1383,7 +1384,35 @@ public class CarpetExpression
return (_c, _t) -> ret;
});
this.expr.addLazyFunction("add_chunk_ticket", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext)c;
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
BlockPos pos = locator.block.getPos();
if (lv.size() != locator.offset+2) throw new InternalExpressionException("'add_chunk_ticket' requires block position, ticket type and radius");
String type = lv.get(locator.offset).evalValue(c).getString();
ChunkTicketType ticket = ticketTypes.get(type.toLowerCase(Locale.ROOT));
if (ticket == null) throw new InternalExpressionException("Unknown ticket type: "+type);
int radius = NumericValue.asNumber(lv.get(locator.offset+1).evalValue(c)).getInt();
if (radius < 1 || radius > 32) throw new InternalExpressionException("Ticket radius should be between 1 and 32 chunks");
// due to types we will wing it:
ChunkPos target = new ChunkPos(pos);
if (ticket == ChunkTicketType.PORTAL)
cc.s.getWorld().getChunkManager().addTicket(ChunkTicketType.PORTAL, target, radius, pos);
else if (ticket == ChunkTicketType.POST_TELEPORT)
cc.s.getWorld().getChunkManager().addTicket(ChunkTicketType.POST_TELEPORT, target, radius, 1);
else
cc.s.getWorld().getChunkManager().addTicket(ChunkTicketType.UNKNOWN, target, radius, target);
Value ret = new NumericValue(ticket.getExpiryTicks());
return (_c, _t) -> ret;
});
}
private Map<String, ChunkTicketType<?>> ticketTypes = new HashMap<String, ChunkTicketType<?>>(){{
put("portal", ChunkTicketType.PORTAL);
put("teleport", ChunkTicketType.POST_TELEPORT);
put("unknown", ChunkTicketType.UNKNOWN);
}};
private static String getScoreboardKeyFromValue(Value keyValue)
{