forked from SteamWar/SteamWar
Fix packet count to at most 2 for the display entities at spawn
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
public class RBlockDisplay extends RDisplay {
|
||||
|
||||
private BlockData block = Material.AIR.createBlockData();
|
||||
public static final BlockData DEFAULT_BLOCK = Material.AIR.createBlockData();
|
||||
|
||||
private BlockData block = DEFAULT_BLOCK;
|
||||
|
||||
public RBlockDisplay(REntityServer server, Location location) {
|
||||
super(server, EntityType.BLOCK_DISPLAY, location);
|
||||
@@ -24,22 +25,19 @@ public class RBlockDisplay extends RDisplay {
|
||||
@Override
|
||||
protected void postSpawn(Consumer<Object> packetSink) {
|
||||
super.postSpawn(packetSink);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
sendBlock(packetSink);
|
||||
}, 0);
|
||||
sendPacket(packetSink, this::getBlock);
|
||||
}
|
||||
|
||||
public void setBlock(BlockData block) {
|
||||
this.block = block;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendBlock(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getBlock);
|
||||
}
|
||||
|
||||
private static final Class<?> iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData");
|
||||
private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass);
|
||||
private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass);
|
||||
private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass);
|
||||
private void sendBlock(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(blockWatcher, getState.invoke(block)));
|
||||
private void getBlock(BiConsumer<Object, Object> packetSink) {
|
||||
if (block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) return;
|
||||
packetSink.accept(blockWatcher, getState.invoke(block));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,18 @@ import org.bukkit.util.Transformation;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
public abstract class RDisplay extends REntity {
|
||||
|
||||
private Transformation transform = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1));
|
||||
protected final Consumer<Object> updatePacketSink = o -> server.updateEntity(this, o);
|
||||
|
||||
public static final Transformation DEFAULT_TRANSFORM = new Transformation(new Vector3f(), new Quaternionf(0, 0, 0, 1), new Vector3f(1, 1, 1), new Quaternionf(0, 0, 0, 1));
|
||||
private Transformation transform = DEFAULT_TRANSFORM;
|
||||
|
||||
private int interpolationDuration = 0;
|
||||
|
||||
@@ -41,169 +47,171 @@ public abstract class RDisplay extends REntity {
|
||||
private Display.Brightness brightness = null;
|
||||
|
||||
protected RDisplay(REntityServer server, EntityType entityType, Location location) {
|
||||
super(server, entityType, location);
|
||||
super(server, entityType, location, 0);
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> server.addEntity(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postSpawn(Consumer<Object> packetSink) {
|
||||
super.postSpawn(packetSink);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
sendTransform(packetSink);
|
||||
sendInterpolationDuration(packetSink);
|
||||
sendViewRange(packetSink);
|
||||
sendShadowRadius(packetSink);
|
||||
sendShadowStrength(packetSink);
|
||||
sendDisplayWidth(packetSink);
|
||||
sendDisplayHeight(packetSink);
|
||||
sendInterpolationDelay(packetSink);
|
||||
sendBillboard(packetSink);
|
||||
sendGlowColorOverride(packetSink);
|
||||
sendBrightness(packetSink);
|
||||
}, 0);
|
||||
sendPacket(packetSink,
|
||||
this::getTransformData,
|
||||
this::getInterpolationDuration,
|
||||
this::getViewRange,
|
||||
this::getShadowRadius,
|
||||
this::getShadowStrength,
|
||||
this::getDisplayWidth,
|
||||
this::getDisplayHeight,
|
||||
this::getInterpolationDelay,
|
||||
this::getBillboard,
|
||||
this::getGlowColorOverride,
|
||||
this::getBrightness
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void sendPacket(Consumer<Object> packetSink, Consumer<BiConsumer<Object, Object>>... dataSinkSinks) {
|
||||
List<Object> keyValueData = new ArrayList<>();
|
||||
for (Consumer<BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept((dataWatcher, value) -> {
|
||||
keyValueData.add(dataWatcher);
|
||||
keyValueData.add(value);
|
||||
});
|
||||
}
|
||||
if (keyValueData.isEmpty()) return;
|
||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
||||
}
|
||||
|
||||
public void setTransform(@NonNull Transformation transform) {
|
||||
this.transform = transform;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTransform(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTransformData);
|
||||
}
|
||||
|
||||
private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class);
|
||||
private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class);
|
||||
private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class);
|
||||
private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class);
|
||||
private void sendTransform(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(translationWatcher, transform.getTranslation()));
|
||||
packetSink.accept(getDataWatcherPacket(leftRotationWatcher, transform.getLeftRotation()));
|
||||
packetSink.accept(getDataWatcherPacket(scaleWatcher, transform.getScale()));
|
||||
packetSink.accept(getDataWatcherPacket(rightRotationWatcher, transform.getRightRotation()));
|
||||
private void getTransformData(BiConsumer<Object, Object> dataSink) {
|
||||
if (transform.equals(DEFAULT_TRANSFORM)) return;
|
||||
dataSink.accept(translationWatcher, transform.getTranslation());
|
||||
dataSink.accept(leftRotationWatcher, transform.getLeftRotation());
|
||||
dataSink.accept(scaleWatcher, transform.getScale());
|
||||
dataSink.accept(rightRotationWatcher, transform.getRightRotation());
|
||||
}
|
||||
|
||||
public void setInterpolationDuration(int interpolationDuration) {
|
||||
this.interpolationDuration = interpolationDuration;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendInterpolationDuration(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getInterpolationDuration);
|
||||
}
|
||||
|
||||
private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class);
|
||||
private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class);
|
||||
private void sendInterpolationDuration(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(transformationInterpolationDurationWatcher, interpolationDuration));
|
||||
packetSink.accept(getDataWatcherPacket(positionOrRotationInterpolationDurationWatcher, interpolationDuration));
|
||||
private void getInterpolationDuration(BiConsumer<Object, Object> packetSink) {
|
||||
if (interpolationDelay == 0) return;
|
||||
packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration);
|
||||
packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration);
|
||||
}
|
||||
|
||||
public void setViewRange(float viewRange) {
|
||||
this.viewRange = viewRange;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendViewRange(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getViewRange);
|
||||
}
|
||||
|
||||
private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class);
|
||||
private void sendViewRange(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(viewRangeWatcher, viewRange));
|
||||
private void getViewRange(BiConsumer<Object, Object> packetSink) {
|
||||
if (viewRange == 1.0F) return;
|
||||
packetSink.accept(viewRangeWatcher, viewRange);
|
||||
}
|
||||
|
||||
public void setShadowRadius(float shadowRadius) {
|
||||
this.shadowRadius = shadowRadius;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendShadowRadius(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getShadowRadius);
|
||||
}
|
||||
|
||||
private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class);
|
||||
private void sendShadowRadius(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(shadowRadiusWatcher, shadowRadius));
|
||||
private void getShadowRadius(BiConsumer<Object, Object> packetSink) {
|
||||
if (shadowRadius == 1.0F) return;
|
||||
packetSink.accept(shadowRadiusWatcher, shadowRadius);
|
||||
}
|
||||
|
||||
public void setShadowStrength(float shadowStrength) {
|
||||
this.shadowStrength = shadowStrength;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendShadowStrength(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getShadowStrength);
|
||||
}
|
||||
|
||||
private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class);
|
||||
private void sendShadowStrength(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(shadowStrengthWatcher, shadowStrength));
|
||||
private void getShadowStrength(BiConsumer<Object, Object> packetSink) {
|
||||
if (shadowStrength == 1.0F) return;
|
||||
packetSink.accept(shadowStrengthWatcher, shadowStrength);
|
||||
}
|
||||
|
||||
public void setDisplayWidth(float displayWidth) {
|
||||
this.displayWidth = displayWidth;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendDisplayWidth(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getDisplayWidth);
|
||||
}
|
||||
|
||||
private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class);
|
||||
private void sendDisplayWidth(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(displayWidthWatcher, displayWidth));
|
||||
private void getDisplayWidth(BiConsumer<Object, Object> packetSink) {
|
||||
if (displayWidth == 0.0F) return;
|
||||
packetSink.accept(displayWidthWatcher, displayWidth);
|
||||
}
|
||||
|
||||
public void setDisplayHeight(float displayHeight) {
|
||||
this.displayHeight = displayHeight;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendDisplayHeight(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getDisplayHeight);
|
||||
}
|
||||
|
||||
private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class);
|
||||
private void sendDisplayHeight(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(displayHeightWatcher, displayHeight));
|
||||
private void getDisplayHeight(BiConsumer<Object, Object> packetSink) {
|
||||
if (displayHeight == 0.0F) return;
|
||||
packetSink.accept(displayHeightWatcher, displayHeight);
|
||||
}
|
||||
|
||||
public void setInterpolationDelay(int interpolationDelay) {
|
||||
this.interpolationDelay = interpolationDelay;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendInterpolationDelay(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getInterpolationDelay);
|
||||
}
|
||||
|
||||
private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class);
|
||||
private void sendInterpolationDelay(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(interpolationDelayWatcher, interpolationDelay));
|
||||
private void getInterpolationDelay(BiConsumer<Object, Object> packetSink) {
|
||||
if (interpolationDelay == 0) return;
|
||||
packetSink.accept(interpolationDelayWatcher, interpolationDelay);
|
||||
}
|
||||
|
||||
public void setBillboard(Display.Billboard billboard) {
|
||||
this.billboard = billboard;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendBillboard(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getBillboard);
|
||||
}
|
||||
|
||||
private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class);
|
||||
private void sendBillboard(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(billboardWatcher, (byte) billboard.ordinal()));
|
||||
private void getBillboard(BiConsumer<Object, Object> packetSink) {
|
||||
if (billboard == Display.Billboard.FIXED) return;
|
||||
packetSink.accept(billboardWatcher, (byte) billboard.ordinal());
|
||||
}
|
||||
|
||||
public void setGlowColorOverride(Color glowColorOverride) {
|
||||
this.glowColorOverride = glowColorOverride;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendGlowColorOverride(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getGlowColorOverride);
|
||||
}
|
||||
|
||||
private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class);
|
||||
private void sendGlowColorOverride(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(glowColorOverrideWatcher, glowColorOverride));
|
||||
private void getGlowColorOverride(BiConsumer<Object, Object> packetSink) {
|
||||
if (glowColorOverride == null) return;
|
||||
packetSink.accept(glowColorOverrideWatcher, glowColorOverride);
|
||||
}
|
||||
|
||||
public void setBrightness(Display.Brightness brightness) {
|
||||
this.brightness = brightness;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendBrightness(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getBrightness);
|
||||
}
|
||||
|
||||
private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class);
|
||||
private void sendBrightness(Consumer<Object> packetSink) {
|
||||
private void getBrightness(BiConsumer<Object, Object> packetSink) {
|
||||
if (brightness == null) {
|
||||
packetSink.accept(getDataWatcherPacket(brightnessWatcher, -1));
|
||||
packetSink.accept(brightnessWatcher, -1); // TODO: Potentially not needed, need to test/investigate
|
||||
} else {
|
||||
int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20;
|
||||
packetSink.accept(getDataWatcherPacket(brightnessWatcher, brightnessData));
|
||||
packetSink.accept(brightnessWatcher, brightnessData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
public class RItemDisplay extends RDisplay {
|
||||
|
||||
private ItemStack itemStack;
|
||||
public static final ItemStack DEFAULT_ITEM_STACK = new ItemStack(Material.AIR);
|
||||
|
||||
private ItemDisplay.ItemDisplayTransform itemDisplayTransform;
|
||||
private ItemStack itemStack = DEFAULT_ITEM_STACK;
|
||||
|
||||
private ItemDisplay.ItemDisplayTransform itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE;
|
||||
|
||||
public RItemDisplay(REntityServer server, Location location) {
|
||||
super(server, EntityType.ITEM_DISPLAY, location);
|
||||
@@ -26,35 +28,28 @@ public class RItemDisplay extends RDisplay {
|
||||
@Override
|
||||
protected void postSpawn(Consumer<Object> packetSink) {
|
||||
super.postSpawn(packetSink);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
sendItemStack(packetSink);
|
||||
sendItemDisplayTransform(packetSink);
|
||||
}, 0);
|
||||
sendPacket(packetSink, this::getItemStack, this::getItemDisplayTransform);
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendItemStack(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getItemStack);
|
||||
}
|
||||
|
||||
private static final Class<?> itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack");
|
||||
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class);
|
||||
private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStackClass, ItemStack.class);
|
||||
private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, itemStackClass);
|
||||
private void sendItemStack(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(itemStackWatcher, asNMSCopy.invoke(null, itemStack)));
|
||||
private void getItemStack(BiConsumer<Object, Object> packetSink) {
|
||||
packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack));
|
||||
}
|
||||
|
||||
private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class);
|
||||
public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) {
|
||||
this.itemDisplayTransform = itemDisplayTransform;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendItemDisplayTransform(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getItemDisplayTransform);
|
||||
}
|
||||
|
||||
private void sendItemDisplayTransform(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal()));
|
||||
private void getItemDisplayTransform(BiConsumer<Object, Object> packetSink) {
|
||||
packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.ChatWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.TextDisplay;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
@@ -36,81 +35,65 @@ public class RTextDisplay extends RDisplay {
|
||||
@Override
|
||||
protected void postSpawn(Consumer<Object> packetSink) {
|
||||
super.postSpawn(packetSink);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
sendText(packetSink);
|
||||
sendLineWidth(packetSink);
|
||||
sendTextOpacity(packetSink);
|
||||
sendTextStatus(packetSink);
|
||||
}, 0);
|
||||
sendPacket(packetSink, this::getText, this::getLineWidth, this::getTextOpacity, this::getTextStatus);
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendText(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getText);
|
||||
}
|
||||
|
||||
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
|
||||
private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent);
|
||||
private void sendText(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(textWatcher, ChatWrapper.impl.stringToChatComponent(text)));
|
||||
private void getText(BiConsumer<Object, Object> packetSink) {
|
||||
if (text.isEmpty()) return;
|
||||
packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text));
|
||||
}
|
||||
|
||||
public void setLineWidth(int lineWidth) {
|
||||
this.lineWidth = lineWidth;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendLineWidth(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getLineWidth);
|
||||
}
|
||||
|
||||
private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class);
|
||||
private void sendLineWidth(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(lineWidthWatcher, lineWidth));
|
||||
private void getLineWidth(BiConsumer<Object, Object> packetSink) {
|
||||
if (lineWidth == 200) return;
|
||||
packetSink.accept(lineWidthWatcher, lineWidth);
|
||||
}
|
||||
|
||||
public void setTextOpacity(byte textOpacity) {
|
||||
this.textOpacity = textOpacity;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTextOpacity(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTextOpacity);
|
||||
}
|
||||
|
||||
private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class);
|
||||
private void sendTextOpacity(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getDataWatcherPacket(textOpacityWatcher, textOpacity));
|
||||
private void getTextOpacity(BiConsumer<Object, Object> packetSink) {
|
||||
if (textOpacity == (byte) -1) return;
|
||||
packetSink.accept(textOpacityWatcher, textOpacity);
|
||||
}
|
||||
|
||||
public void setShadowed(boolean shadowed) {
|
||||
this.shadowed = shadowed;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTextStatus(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTextStatus);
|
||||
}
|
||||
|
||||
public void setSeeThrough(boolean seeThrough) {
|
||||
this.seeThrough = seeThrough;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTextStatus(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTextStatus);
|
||||
}
|
||||
|
||||
public void setDefaultBackground(boolean defaultBackground) {
|
||||
this.defaultBackground = defaultBackground;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTextStatus(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTextStatus);
|
||||
}
|
||||
|
||||
public void setAlignment(TextDisplay.TextAlignment alignment) {
|
||||
this.alignment = alignment;
|
||||
if (Core.getVersion() >= 20) {
|
||||
sendTextStatus(o -> server.updateEntity(this, o));
|
||||
}
|
||||
sendPacket(updatePacketSink, this::getTextStatus);
|
||||
}
|
||||
|
||||
private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class);
|
||||
private void sendTextStatus(Consumer<Object> packetSink) {
|
||||
private void getTextStatus(BiConsumer<Object, Object> packetSink) {
|
||||
byte status = 0;
|
||||
|
||||
if (shadowed) {
|
||||
@@ -130,6 +113,7 @@ public class RTextDisplay extends RDisplay {
|
||||
status |= 0x0F;
|
||||
}
|
||||
|
||||
packetSink.accept(getDataWatcherPacket(textStatusWatcher, status));
|
||||
if (status == 0) return;
|
||||
packetSink.accept(textStatusWatcher, status);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user