work on distance_beta
This commit is contained in:
1 parent
d980ab6d91
commit
4bf0a2a088
2 files changed
+103
-57
No files matched your search
@@ -63,6 +63,7 @@ import net.minecraft.command.argument.RotationArgumentType;
|
|||||||
import net.minecraft.command.argument.ScoreHolderArgumentType;
|
import net.minecraft.command.argument.ScoreHolderArgumentType;
|
||||||
import net.minecraft.command.argument.ScoreboardSlotArgumentType;
|
import net.minecraft.command.argument.ScoreboardSlotArgumentType;
|
||||||
import net.minecraft.command.argument.SwizzleArgumentType;
|
import net.minecraft.command.argument.SwizzleArgumentType;
|
||||||
|
import net.minecraft.command.argument.TeamArgumentType;
|
||||||
import net.minecraft.command.argument.TimeArgumentType;
|
import net.minecraft.command.argument.TimeArgumentType;
|
||||||
import net.minecraft.command.argument.UuidArgumentType;
|
import net.minecraft.command.argument.UuidArgumentType;
|
||||||
import net.minecraft.command.argument.Vec2ArgumentType;
|
import net.minecraft.command.argument.Vec2ArgumentType;
|
||||||
@@ -130,7 +131,6 @@ public abstract class CommandArgument
|
|||||||
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgumentType::blockPredicate,
|
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgumentType::blockPredicate,
|
||||||
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getMinecraftServer().getTagManager(), BlockPredicateArgumentType.getBlockPredicate(c, p)), false
|
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getMinecraftServer().getTagManager(), BlockPredicateArgumentType.getBlockPredicate(c, p)), false
|
||||||
),
|
),
|
||||||
// block_predicate todo - not sure about the returned format. Needs to match block tags used in the API (future)
|
|
||||||
new VanillaUnconfigurableArgument("teamcolor", ColorArgumentType::color,
|
new VanillaUnconfigurableArgument("teamcolor", ColorArgumentType::color,
|
||||||
(c, p) -> {
|
(c, p) -> {
|
||||||
Formatting format = ColorArgumentType.getColor(c, p);
|
Formatting format = ColorArgumentType.getColor(c, p);
|
||||||
@@ -165,7 +165,6 @@ public abstract class CommandArgument
|
|||||||
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getId(ItemEnchantmentArgumentType.getEnchantment(c, p))), false
|
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getId(ItemEnchantmentArgumentType.getEnchantment(c, p))), false
|
||||||
),
|
),
|
||||||
// item_predicate ?? //same as item but accepts tags, not sure right now
|
// item_predicate ?? //same as item but accepts tags, not sure right now
|
||||||
// slot // item_slot
|
|
||||||
new SlotArgument(),
|
new SlotArgument(),
|
||||||
new VanillaUnconfigurableArgument("item", ItemStackArgumentType::itemStack,
|
new VanillaUnconfigurableArgument("item", ItemStackArgumentType::itemStack,
|
||||||
(c, p) -> ValueConversions.of(ItemStackArgumentType.getItemStackArgument(c, p).createStack(1, false)), false
|
(c, p) -> ValueConversions.of(ItemStackArgumentType.getItemStackArgument(c, p).createStack(1, false)), false
|
||||||
@@ -241,7 +240,9 @@ public abstract class CommandArgument
|
|||||||
new VanillaUnconfigurableArgument("swizzle", SwizzleArgumentType::swizzle,
|
new VanillaUnconfigurableArgument("swizzle", SwizzleArgumentType::swizzle,
|
||||||
(c, p) -> StringValue.of(SwizzleArgumentType.getSwizzle(c, p).stream().map(Direction.Axis::asString).collect(Collectors.joining())), true
|
(c, p) -> StringValue.of(SwizzleArgumentType.getSwizzle(c, p).stream().map(Direction.Axis::asString).collect(Collectors.joining())), true
|
||||||
),
|
),
|
||||||
// team
|
new VanillaUnconfigurableArgument("team", TeamArgumentType::team,
|
||||||
|
(c, p) -> StringValue.of(TeamArgumentType.getTeam(c, p).getName()), false
|
||||||
|
),
|
||||||
new VanillaUnconfigurableArgument("time", TimeArgumentType::time,
|
new VanillaUnconfigurableArgument("time", TimeArgumentType::time,
|
||||||
(c, p) -> new NumericValue(IntegerArgumentType.getInteger(c, p)), false
|
(c, p) -> new NumericValue(IntegerArgumentType.getInteger(c, p)), false
|
||||||
),
|
),
|
||||||
@@ -437,7 +438,7 @@ public abstract class CommandArgument
|
|||||||
if (config.containsKey("options"))
|
if (config.containsKey("options"))
|
||||||
{
|
{
|
||||||
Value optionsValue = config.get("options");
|
Value optionsValue = config.get("options");
|
||||||
if (!(optionsValue instanceof ListValue)) throw new InternalExpressionException("Custom sting type requires options passed as a list");
|
if (!(optionsValue instanceof ListValue)) throw new InternalExpressionException("Custom string type requires options passed as a list");
|
||||||
validOptions = ((ListValue) optionsValue).getItems().stream()
|
validOptions = ((ListValue) optionsValue).getItems().stream()
|
||||||
.map(v -> caseSensitive?v.getString():(v.getString().toLowerCase(Locale.ROOT)))
|
.map(v -> caseSensitive?v.getString():(v.getString().toLowerCase(Locale.ROOT)))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|||||||
@@ -1,91 +1,136 @@
|
|||||||
import('math','_euclidean','_manhattan','_round');
|
import('math','_euclidean','_manhattan','_round');
|
||||||
|
|
||||||
|
global_display_modes = ['none', 'line', 'centered_sphere', 'box'];
|
||||||
|
|
||||||
__config()->{
|
__config()->{
|
||||||
'commands'->{
|
'commands'->{
|
||||||
'from <start>'->'set_start',
|
'from <start>'->'set_start',
|
||||||
'from <start> to <end>'->'_calculate',
|
'from <start> to <end>'-> _(start, end) -> (global_current_start = start; calculate(end)),
|
||||||
'to <end>'->_(end_pos)->(_calculate(null,end_pos)),
|
'to <end>'-> 'calculate',
|
||||||
'toggle_line'->'_toggle_line'
|
'clear' -> _() -> global_display_shapes = [],
|
||||||
|
'clear last' -> _() -> if(global_display_shapes, delete(global_display_shapes, -1)),
|
||||||
|
'display <mode>' -> 'set_mode'
|
||||||
},
|
},
|
||||||
'arguments' -> {
|
'arguments' -> {
|
||||||
'start' -> {'type' -> 'location'},
|
'start' -> {'type' -> 'location'},
|
||||||
'end' -> {'type' -> 'location'}
|
'end' -> {'type' -> 'location'},
|
||||||
|
'mode' -> {'type' -> 'term', 'options' -> global_display_modes }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
global_start=null;
|
global_current_start = null;
|
||||||
global_end=null;
|
global_display_shapes = [];
|
||||||
|
global_renderer_running = false;
|
||||||
|
|
||||||
global_show_line=false;
|
|
||||||
|
global_current_mode = 'none';
|
||||||
|
global_generators = {
|
||||||
|
'line' -> _(from, to) -> [
|
||||||
|
['line',20,'from',from,'to',to],
|
||||||
|
['label',20,'pos',to+[0,0.2,0],'text',_round(_euclidean(from,to),0.001)]
|
||||||
|
],
|
||||||
|
'centered_sphere' -> _(from, to) -> [
|
||||||
|
['line',20,'from',from,'to',to, 'line', 5, 'color', 0x88888888],
|
||||||
|
['sphere',20,'center',from,'radius',_euclidean(from,to)],
|
||||||
|
['label',20,'pos',to+[0,0.2,0],'text',_round(_euclidean(from,to),0.001)]
|
||||||
|
],
|
||||||
|
'box' -> _(from, to) -> [
|
||||||
|
['line',20,'from',from,'to',to, 'line', 5, 'color', 0x88888888],
|
||||||
|
['box',20,'from',from,'to',to],
|
||||||
|
['label',20,'pos',to+[0,0.2,0],'text',_round(_euclidean(from,to),0.001)]
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
__mktp(pos) -> str('!/tp %.6f %.6f %.6f', pos);
|
__mktp(pos) -> str('!/tp %.6f %.6f %.6f', pos);
|
||||||
|
|
||||||
set_start(pos)->(
|
set_start(pos)->(
|
||||||
global_start = pos;
|
global_current_start = pos;
|
||||||
global_end = null;
|
|
||||||
print(player(),format('gi Initial point set to: ', 'g '+pos, __mktp(pos)))
|
print(player(),format('gi Initial point set to: ', 'g '+pos, __mktp(pos)))
|
||||||
);
|
);
|
||||||
|
|
||||||
_toggle_line()->(
|
set_mode(mode)->(
|
||||||
global_show_line= !global_show_line;
|
if (global_display_modes ~ mode,
|
||||||
if(global_show_line,
|
global_current_mode = mode
|
||||||
print('Toggled lines on');
|
|
||||||
_draw_line()
|
|
||||||
, // else
|
|
||||||
print('Toggled lines off')
|
|
||||||
);
|
|
||||||
);
|
|
||||||
|
|
||||||
_calculate(start_pos, end_pos)->(
|
|
||||||
if(start_pos!=null,
|
|
||||||
set_start(start_pos);
|
|
||||||
calculate(end_pos)
|
|
||||||
, // else
|
|
||||||
if(global_start,
|
|
||||||
calculate(end_pos),
|
|
||||||
print(player(),format('r There was no initial point for '+player()));
|
|
||||||
set_start(end_pos)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
__on_player_places_block(player, item_tuple, hand, block) ->(
|
calculate(end)->(
|
||||||
if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true',
|
if(global_current_start != null,
|
||||||
|
measure(end)
|
||||||
|
, // else
|
||||||
|
print(player(),format('r No initial point selected'));
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
_carpets() -> system_info('world_carpet_rules'):'carpets'=='true';
|
||||||
|
|
||||||
|
|
||||||
|
__on_player_places_block(player, item_tuple, hand, block) ->
|
||||||
|
(
|
||||||
|
if(block=='brown_carpet' && _carpets(),
|
||||||
effective_pos = pos(block)+[0.5, 0, 0.5];
|
effective_pos = pos(block)+[0.5, 0, 0.5];
|
||||||
if(global_start==null||player~'sneaking',//wont complain for first carpet
|
if(global_current_start==null||player~'sneaking',//wont complain for first carpet
|
||||||
set_start(effective_pos),
|
set_start(effective_pos)
|
||||||
_calculate(null, effective_pos)
|
, // else
|
||||||
|
calculate(effective_pos)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
calculate(end_pos)->(
|
__on_player_uses_item(player, item_tuple, hand) ->
|
||||||
global_end = end_pos;
|
(
|
||||||
manhattan = _round(_manhattan(global_start, global_end),0.001);//rounding to nearest 0.01 for precision, but not ridiculous decimal places
|
if (item_tuple:0 == 'brown_carpet' && hand == 'mainhand' && _carpets(),
|
||||||
spherical = _round(_euclidean(global_start, global_end), 0.001);
|
if (player ~'sneaking',
|
||||||
|
global_current_mode = global_display_modes:(global_display_modes ~ global_current_mode + 1);
|
||||||
|
display_title(player, 'actionbar', format('w Distance mode: ','e '+global_current_mode));
|
||||||
|
,
|
||||||
|
if(global_display_shapes, delete(global_display_shapes, -1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
measure(end)->
|
||||||
|
(
|
||||||
|
if (global_current_start == null, return());
|
||||||
|
start = global_current_start;
|
||||||
|
manhattan = _round(_manhattan(start, end),0.001);//rounding to nearest 0.01 for precision, but not ridiculous decimal places
|
||||||
|
spherical = _round(_euclidean(start, end), 0.001);
|
||||||
//useful for chunk distances etc.
|
//useful for chunk distances etc.
|
||||||
cylindrical = _round(_euclidean(global_start, [global_end:0, global_start:1, global_end:2]), 0.001);
|
cylindrical = _round(_euclidean(start, [end:0, start:1, end:2]), 0.001);
|
||||||
|
|
||||||
|
|
||||||
print(player(),format(
|
print(player(),format(
|
||||||
'w Distance between ',
|
'w Distance between ',
|
||||||
'c '+str('[%.1f, %.1f, %.1f]', global_start), __mktp(global_start),
|
'c '+str('[%.1f, %.1f, %.1f]', start), __mktp(start),
|
||||||
'w and ',
|
'w and ',
|
||||||
'c '+str('[%.1f, %.1f, %.1f]', global_end), __mktp(global_end), 'w :\n',
|
'c '+str('[%.1f, %.1f, %.1f]', end), __mktp(end), 'w :\n',
|
||||||
'w - Spherical: ', 'wb '+spherical+'\n',
|
'w - Spherical: ', 'wb '+spherical+'\n',
|
||||||
'w - Cylindrical: ', 'wb '+cylindrical+'\n',
|
'w - Cylindrical: ', 'wb '+cylindrical+'\n',
|
||||||
'w - Manhattan: ', 'wb '+manhattan
|
'w - Manhattan: ', 'wb '+manhattan
|
||||||
));
|
));
|
||||||
|
if (global_current_mode != 'none',
|
||||||
schedule(0,'_draw_line');
|
global_display_shapes += _create_shapes(global_current_mode, start, end);
|
||||||
);
|
for (global_display_shapes, draw_shape(_) );
|
||||||
|
if (!global_renderer_running,
|
||||||
_draw_line()->(
|
global_renderer_running = true;
|
||||||
if(global_show_line,//It will always draw from the global positions, so it will turn on if there is a line
|
render()
|
||||||
if ( global_start && global_end,
|
)
|
||||||
draw_shape('line',20,'from',global_start,'to',global_end, 'player',player());
|
|
||||||
draw_shape('label',20,'pos',global_end,'text',_round(_euclidean(global_start,global_end),0.001));
|
|
||||||
);
|
|
||||||
schedule(20,'_draw_line')
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_create_shapes(mode, from, to) ->
|
||||||
|
(
|
||||||
|
|
||||||
|
shapes = call(global_generators:mode, from+[0, 0.07, 0], to+[0, 0.07, 0]);
|
||||||
|
map(shapes, put(_, null, ['player', player()], 'extend'); _);
|
||||||
|
);
|
||||||
|
|
||||||
|
render()->(
|
||||||
|
if (!global_display_shapes,
|
||||||
|
global_renderer_running = false;
|
||||||
|
return();
|
||||||
|
);
|
||||||
|
for (global_display_shapes,
|
||||||
|
draw_shape(_);
|
||||||
|
);
|
||||||
|
schedule(20,'render')
|
||||||
|
);
|
||||||
Reference in new issue
Block a user