refactor access to context data
This commit is contained in:
1 parent
bc31faca21
commit
8dd08d5cb1
15 files changed
+239
-194
No files matched your search
@@ -3,11 +3,16 @@ package carpet.script;
|
||||
import carpet.script.value.Value;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
public class CarpetContext extends Context
|
||||
{
|
||||
public CommandSourceStack s;
|
||||
public final BlockPos origin;
|
||||
private CommandSourceStack s;
|
||||
private final BlockPos origin;
|
||||
|
||||
public CarpetContext(CarpetScriptHost host, CommandSourceStack source) {
|
||||
this(host, source, BlockPos.ZERO);
|
||||
@@ -34,4 +39,38 @@ public class CarpetContext extends Context
|
||||
variables.put("_y", (c, t) -> Value.ZERO);
|
||||
variables.put("_z", (c, t) -> Value.ZERO);
|
||||
}
|
||||
|
||||
public MinecraftServer server()
|
||||
{
|
||||
return s.getServer();
|
||||
}
|
||||
|
||||
public ServerLevel level()
|
||||
{
|
||||
return s.getLevel();
|
||||
}
|
||||
|
||||
public RegistryAccess registryAccess()
|
||||
{
|
||||
return s.getLevel().registryAccess();
|
||||
}
|
||||
|
||||
public <T> Registry<T> registry(ResourceKey<? extends Registry<? extends T>> resourceKey) {
|
||||
return registryAccess().registryOrThrow(resourceKey);
|
||||
}
|
||||
|
||||
public CommandSourceStack source()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
public BlockPos origin()
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
|
||||
public void swapSource(CommandSourceStack source)
|
||||
{
|
||||
s = source;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user