forked from SteamWar/SteamWar
Reduce spawn packets to 0 if everything is default
This commit is contained in:
@@ -16,10 +16,12 @@ public class RBlockDisplay extends RDisplay {
|
||||
|
||||
public static final BlockData DEFAULT_BLOCK = Material.AIR.createBlockData();
|
||||
|
||||
private BlockData block = DEFAULT_BLOCK;
|
||||
private BlockData block;
|
||||
|
||||
public RBlockDisplay(REntityServer server, Location location) {
|
||||
super(server, EntityType.BLOCK_DISPLAY, location);
|
||||
this.block = DEFAULT_BLOCK;
|
||||
server.addEntity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,8 +35,8 @@ public class RBlockDisplay extends RDisplay {
|
||||
sendPacket(updatePacketSink, this::getBlock);
|
||||
}
|
||||
|
||||
private static final Class<?> iBlockDataClass = Reflection.getClass("{nms.world}.level.block.state.IBlockData");
|
||||
private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", iBlockDataClass);
|
||||
private static final Class<?> iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState");
|
||||
private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass);
|
||||
private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass);
|
||||
private void getBlock(BiConsumer<Object, Object> packetSink) {
|
||||
if (block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) return;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Display;
|
||||
@@ -24,31 +22,32 @@ public abstract class RDisplay extends REntity {
|
||||
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;
|
||||
|
||||
private float viewRange = 1.0F;
|
||||
|
||||
private float shadowRadius = 0.0F;
|
||||
|
||||
private float shadowStrength = 1.0F;
|
||||
|
||||
private float displayWidth = 0.0F;
|
||||
|
||||
private float displayHeight = 0.0F;
|
||||
|
||||
private int interpolationDelay = 0;
|
||||
|
||||
private Display.Billboard billboard = Display.Billboard.FIXED;
|
||||
|
||||
private Color glowColorOverride = null;
|
||||
|
||||
private Display.Brightness brightness = null;
|
||||
private Transformation transform;
|
||||
private int interpolationDuration;
|
||||
private float viewRange;
|
||||
private float shadowRadius;
|
||||
private float shadowStrength;
|
||||
private float displayWidth;
|
||||
private float displayHeight;
|
||||
private int interpolationDelay;
|
||||
private Display.Billboard billboard;
|
||||
private Color glowColorOverride;
|
||||
private Display.Brightness brightness;
|
||||
|
||||
protected RDisplay(REntityServer server, EntityType entityType, Location location) {
|
||||
super(server, entityType, location, 0);
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> server.addEntity(this));
|
||||
this.transform = DEFAULT_TRANSFORM;
|
||||
this.interpolationDuration = 0;
|
||||
this.viewRange = 1.0F;
|
||||
this.shadowRadius = 0.0F;
|
||||
this.shadowStrength = 1.0F;
|
||||
this.displayWidth = 0.0F;
|
||||
this.displayHeight = 0.0F;
|
||||
this.interpolationDelay = 0;
|
||||
this.billboard = Display.Billboard.FIXED;
|
||||
this.glowColorOverride = null;
|
||||
this.brightness = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +129,7 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class);
|
||||
private void getShadowRadius(BiConsumer<Object, Object> packetSink) {
|
||||
if (shadowRadius == 1.0F) return;
|
||||
if (shadowRadius == 0.0F) return;
|
||||
packetSink.accept(shadowRadiusWatcher, shadowRadius);
|
||||
}
|
||||
|
||||
@@ -207,11 +206,8 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class);
|
||||
private void getBrightness(BiConsumer<Object, Object> packetSink) {
|
||||
if (brightness == null) {
|
||||
packetSink.accept(brightnessWatcher, -1); // TODO: Potentially not needed, need to test/investigate
|
||||
} else {
|
||||
int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20;
|
||||
packetSink.accept(brightnessWatcher, brightnessData);
|
||||
}
|
||||
if (brightness == null) return;
|
||||
int brightnessData = brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20;
|
||||
packetSink.accept(brightnessWatcher, brightnessData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ public class REntity {
|
||||
private static final Reflection.Field<Integer> equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0);
|
||||
|
||||
private static final Class<?> craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack");
|
||||
private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class);
|
||||
protected static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class);
|
||||
protected Object getEquipmentPacket(Object slot, ItemStack stack){
|
||||
Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket);
|
||||
equipmentEntity.set(packet, entityId);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.ProtocolWrapper;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -17,12 +17,14 @@ public class RItemDisplay extends RDisplay {
|
||||
|
||||
public static final ItemStack DEFAULT_ITEM_STACK = new ItemStack(Material.AIR);
|
||||
|
||||
private ItemStack itemStack = DEFAULT_ITEM_STACK;
|
||||
|
||||
private ItemDisplay.ItemDisplayTransform itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE;
|
||||
private ItemStack itemStack;
|
||||
private ItemDisplay.ItemDisplayTransform itemDisplayTransform;
|
||||
|
||||
public RItemDisplay(REntityServer server, Location location) {
|
||||
super(server, EntityType.ITEM_DISPLAY, location);
|
||||
this.itemStack = DEFAULT_ITEM_STACK;
|
||||
this.itemDisplayTransform = ItemDisplay.ItemDisplayTransform.NONE;
|
||||
server.addEntity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,10 +38,9 @@ public class RItemDisplay extends RDisplay {
|
||||
sendPacket(updatePacketSink, this::getItemStack);
|
||||
}
|
||||
|
||||
private static final Class<?> itemStackClass = Reflection.getClass("{nms.world}.item.ItemStack");
|
||||
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 static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, ProtocolWrapper.itemStack);
|
||||
private void getItemStack(BiConsumer<Object, Object> packetSink) {
|
||||
if (itemStack.equals(DEFAULT_ITEM_STACK)) return;
|
||||
packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack));
|
||||
}
|
||||
|
||||
@@ -50,6 +51,7 @@ public class RItemDisplay extends RDisplay {
|
||||
}
|
||||
|
||||
private void getItemDisplayTransform(BiConsumer<Object, Object> packetSink) {
|
||||
if (itemDisplayTransform == ItemDisplay.ItemDisplayTransform.NONE) return;
|
||||
packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,22 +14,30 @@ import java.util.function.Consumer;
|
||||
@Getter
|
||||
public class RTextDisplay extends RDisplay {
|
||||
|
||||
private String text = "";
|
||||
private String text;
|
||||
|
||||
private int lineWidth = 200;
|
||||
private int lineWidth;
|
||||
|
||||
private byte textOpacity = (byte) -1;
|
||||
private byte textOpacity;
|
||||
|
||||
private boolean shadowed = false;
|
||||
private boolean shadowed;
|
||||
|
||||
private boolean seeThrough = false;
|
||||
private boolean seeThrough;
|
||||
|
||||
private boolean defaultBackground = false;
|
||||
private boolean defaultBackground;
|
||||
|
||||
private TextDisplay.TextAlignment alignment = TextDisplay.TextAlignment.CENTER;
|
||||
private TextDisplay.TextAlignment alignment;
|
||||
|
||||
public RTextDisplay(REntityServer server, Location location) {
|
||||
super(server, EntityType.TEXT_DISPLAY, location);
|
||||
this.text = "";
|
||||
this.lineWidth = 200;
|
||||
this.textOpacity = (byte) -1;
|
||||
this.shadowed = false;
|
||||
this.seeThrough = false;
|
||||
this.defaultBackground = false;
|
||||
this.alignment = TextDisplay.TextAlignment.CENTER;
|
||||
server.addEntity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +51,7 @@ public class RTextDisplay extends RDisplay {
|
||||
sendPacket(updatePacketSink, this::getText);
|
||||
}
|
||||
|
||||
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
|
||||
private static final Class<?> iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component");
|
||||
private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent);
|
||||
private void getText(BiConsumer<Object, Object> packetSink) {
|
||||
if (text.isEmpty()) return;
|
||||
|
||||
Reference in New Issue
Block a user