- rework on handling /log packets
 - rework on player attack and interaction with entities
 - rework display_title (need recheck)
 - rework packets for structure blocks
This commit is contained in:
gnembon committed 2021-02-24 18:25:16 -04:00
1 parent 3505138351
commit 2cf403057c
12 files changed
+95 -41

No files matched your search

+36 -12
View File
@@ -36,6 +36,11 @@ import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import carpet.utils.Messenger;
import net.minecraft.block.BlockState;
import net.minecraft.class_5888;
import net.minecraft.class_5894;
import net.minecraft.class_5903;
import net.minecraft.class_5904;
import net.minecraft.class_5905;
import net.minecraft.command.DataCommandStorage;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
@@ -47,9 +52,10 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
@@ -85,6 +91,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -497,6 +504,7 @@ public class Auxiliary {
return (_c, _t) -> finalRes; // pass through for variables
});
expression.addLazyFunction("display_title", -1, (c, t, lv) -> {
if (lv.size() < 2) throw new InternalExpressionException("'display_title' needs at least a target, type and message, and optionally times");
Value pVal = lv.get(0).evalValue(c);
if (!(pVal instanceof ListValue)) pVal = ListValue.of(pVal);
@@ -507,26 +515,40 @@ public class Auxiliary {
if (player == null) throw new InternalExpressionException("'display_title' requires a valid online player or a list of players as first argument. "+v.getString()+" is not a player.");
return player;
});
TitleS2CPacket.Action action;
Function<Text, Packet<?>> packetGetter;
//TitleS2CPacket.Action action;
switch (lv.get(1).evalValue(c).getString().toLowerCase(Locale.ROOT))
{
case "title":
action = Action.TITLE;
packetGetter = (x) -> new class_5904(x);
//action = Action.TITLE;
if (lv.size() < 3)
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
break;
case "subtitle":
action = Action.SUBTITLE;
packetGetter = (x) -> new class_5903(x);
if (lv.size() < 3)
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
//action = Action.SUBTITLE;
break;
case "actionbar":
action = Action.ACTIONBAR;
packetGetter = (x) -> new class_5894(x);
if (lv.size() < 3)
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
//action = Action.ACTIONBAR;
break;
case "clear":
action = Action.CLEAR;
packetGetter = (x) -> new class_5888(true); // resetting default fade
//action = Action.CLEAR;
break;
default:
throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar' or 'clear' as second argument");
}
if (action != Action.CLEAR && lv.size() < 3)
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
//if (action != Action.CLEAR && lv.size() < 3)
// throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
Text title = null;
if (lv.size() > 2)
{
@@ -536,17 +558,19 @@ public class Auxiliary {
else
title = new LiteralText(pVal.getString());
}
TitleS2CPacket timesPacket;
class_5905 timesPacket; // TimesPacket
if (lv.size() > 3)
{
int in = NumericValue.asNumber(lv.get(3).evalValue(c),"fade in for display_title" ).getInt();
int stay = NumericValue.asNumber(lv.get(4).evalValue(c),"stay for display_title" ).getInt();
int out = NumericValue.asNumber(lv.get(5).evalValue(c),"fade out for display_title" ).getInt();
timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
timesPacket = new class_5905(in, stay, out);
//timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
}
else timesPacket = null;
TitleS2CPacket packet = new TitleS2CPacket(action, title);
Packet<?> packet = packetGetter.apply(title);
//TitleS2CPacket packet = new TitleS2CPacket(action, title);
AtomicInteger total = new AtomicInteger(0);
targets.forEach(p -> {
if (timesPacket != null) p.networkHandler.sendPacket(timesPacket);
@@ -1356,7 +1356,7 @@ public class WorldAccess {
return;
}
StructureStart<?> start = structures.get(structure);
ChunkPos structureChunkPos = new ChunkPos(start.getChunkX(), start.getChunkZ());
ChunkPos structureChunkPos = start.method_34000(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
BlockBox box = start.getBoundingBox();
for (int chx = box.minX / 16; chx <= box.maxX / 16; chx++)
{