fix broken protocol values

This commit is contained in:
Tofaa 2024-02-05 23:09:12 +04:00
parent 6c56f28a7c
commit ae21d85740
13 changed files with 241 additions and 27 deletions

View file

@ -5,19 +5,17 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment=""> <list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaOffset.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/Color.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/TypeHolder.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code-gen/src/main/resources/offset-calculator.json" afterDir="false" /> <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/Rotation.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityUuidProvider.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityUuidProvider.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/CompatibilityIndex.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/build.gradle" afterDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/Main.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaClass.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/test-plugin/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/test-plugin/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaMethod.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetadataClass.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/code-gen/src/main/resources/EntityMeta.json" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -48,6 +46,24 @@
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" /> <item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="EntityLib" type="f1a62948:ProjectNode" /> <item name="EntityLib" type="f1a62948:ProjectNode" />
</path> </path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="EntityLib" type="f1a62948:ProjectNode" />
<item name="test-plugin" type="2d1252cf:ModuleNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="EntityLib" type="f1a62948:ProjectNode" />
<item name="test-plugin" type="2d1252cf:ModuleNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="EntityLib" type="f1a62948:ProjectNode" />
<item name="test-plugin" type="2d1252cf:ModuleNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
<item name="run paper" type="c8890929:TasksNode$1" />
</path>
</expand> </expand>
<select /> <select />
</tree_state> </tree_state>
@ -97,7 +113,7 @@
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;jdk.selected.JAVA_MODULE&quot;: &quot;corretto-17&quot;, &quot;jdk.selected.JAVA_MODULE&quot;: &quot;corretto-17&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/Github/EntityLib/api/src/main/java/me/tofaa/entitylib/meta&quot;, &quot;last_opened_file_path&quot;: &quot;D:/Github/EntityLib/api/src/main/java/me/tofaa/entitylib/extras&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
@ -112,11 +128,12 @@
}</component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="D:\Github\EntityLib\api\src\main\java\me\tofaa\entitylib\extras" />
<recent name="D:\Github\EntityLib\api\src\main\java\me\tofaa\entitylib\meta" /> <recent name="D:\Github\EntityLib\api\src\main\java\me\tofaa\entitylib\meta" />
<recent name="D:\Github\EntityLib\test-plugin" /> <recent name="D:\Github\EntityLib\test-plugin" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Application.Main"> <component name="RunManager" selected="Gradle.EntityLib:test-plugin [runServer]">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="me.tofaa.entitylib.codegen.Main" /> <option name="MAIN_CLASS_NAME" value="me.tofaa.entitylib.codegen.Main" />
<module name="EntityLib.code-gen.main" /> <module name="EntityLib.code-gen.main" />
@ -220,9 +237,9 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Gradle.EntityLib:test-plugin [runServer]" />
<item itemvalue="Application.Main" /> <item itemvalue="Application.Main" />
<item itemvalue="Gradle.EntityLib [dependencies]" /> <item itemvalue="Gradle.EntityLib [dependencies]" />
<item itemvalue="Gradle.EntityLib:test-plugin [runServer]" />
<item itemvalue="Gradle.PE-EntityMeta [compileTestJava]" /> <item itemvalue="Gradle.PE-EntityMeta [compileTestJava]" />
<item itemvalue="Gradle.EntityLib:test-plugin [shadowJar]" /> <item itemvalue="Gradle.EntityLib:test-plugin [shadowJar]" />
</list> </list>
@ -280,7 +297,8 @@
<workItem from="1706601592145" duration="1670000" /> <workItem from="1706601592145" duration="1670000" />
<workItem from="1706614921404" duration="10508000" /> <workItem from="1706614921404" duration="10508000" />
<workItem from="1706696719616" duration="4783000" /> <workItem from="1706696719616" duration="4783000" />
<workItem from="1706784821835" duration="5673000" /> <workItem from="1706784821835" duration="7882000" />
<workItem from="1706858181164" duration="925000" />
</task> </task>
<servers /> <servers />
</component> </component>

View file

@ -3,6 +3,7 @@ package me.tofaa.entitylib;
import com.github.retrooper.packetevents.PacketEventsAPI; import com.github.retrooper.packetevents.PacketEventsAPI;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
@ -24,6 +25,7 @@ public final class APIConfig {
this.packetEvents = packetEvents; this.packetEvents = packetEvents;
} }
@Blocking
public boolean requiresUpdate() throws IOException { public boolean requiresUpdate() throws IOException {
if (!checkForUpdates) return false; if (!checkForUpdates) return false;
String urlString = "https://api.github.com/repos/Tofaa2/EntityLib/releases/latest"; String urlString = "https://api.github.com/repos/Tofaa2/EntityLib/releases/latest";

View file

@ -6,6 +6,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
* Represents a int provider that gives an id for each entity created. When using EntityLib with platform specific entities (Such as bukkit entities), make sure the id's do not
* conflict with the platform's entity id's.
* {@link DefaultEntityIdProvider} is a default implementation of this interface.
*/
public interface EntityIdProvider { public interface EntityIdProvider {
int provide(@NotNull UUID entityUUID, @NotNull EntityType entityType); int provide(@NotNull UUID entityUUID, @NotNull EntityType entityType);

View file

@ -0,0 +1,55 @@
package me.tofaa.entitylib.extras;
import net.kyori.adventure.util.RGBLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
public final class Color implements RGBLike {
private static final int BIT_MASK = 0xFF;
private final int red, green, blue;
public Color(@Range(from = 0L, to = 255L) int red, @Range(from = 0L, to = 255L) int green, @Range(from = 0L, to = 255L) int blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
public Color(int rgb) {
this((rgb >> 16) & BIT_MASK, (rgb >> 8) & BIT_MASK, rgb & BIT_MASK);
}
public @NotNull Color withRed(@Range(from = 0L, to = 255L) int red) {
return new Color(red, green, blue);
}
public @NotNull Color withGreen(@Range(from = 0L, to = 255L) int green) {
return new Color(red, green, blue);
}
public @NotNull Color withBlue(@Range(from = 0L, to = 255L) int blue) {
return new Color(red, green, blue);
}
public int asRGB() {
int rgb = red;
rgb = (rgb << 8) + green;
return (rgb << 8) + blue;
}
@Override
public @Range(from = 0L, to = 255L) int red() {
return red;
}
@Override
public @Range(from = 0L, to = 255L) int green() {
return green;
}
@Override
public @Range(from = 0L, to = 255L) int blue() {
return blue;
}
}

View file

@ -0,0 +1,85 @@
package me.tofaa.entitylib.extras;
import net.kyori.adventure.util.RGBLike;
import org.jetbrains.annotations.NotNull;
public enum DyeColor implements RGBLike {
WHITE(new Color(0xf9fffe), new Color(0xffffff), new Color(0xf0f0f0), 8),
ORANGE(new Color(0xf9801d), new Color(0xff681f), new Color(0xeb8844), 15),
MAGENTA(new Color(0xc74ebd), new Color(0xff00ff), new Color(0xc354cd), 16),
LIGHT_BLUE(new Color(0x3ab3da), new Color(0x9ac0cd), new Color(0x6689d3), 17),
YELLOW(new Color(0xfed83d), new Color(0xffff00), new Color(0xdecf2a), 18),
LIME(new Color(0x80c71f), new Color(0xbfff00), new Color(0x41cd34), 19),
PINK(new Color(0xf38baa), new Color(0xff69b4), new Color(0xd88198), 20),
GRAY(new Color(0x474f52), new Color(0x808080), new Color(0x434343), 21),
LIGHT_GRAY(new Color(0x9d9d97), new Color(0xd3d3d3), new Color(0xababab), 22),
CYAN(new Color(0x169c9c), new Color(0xffff), new Color(0x287697), 23),
PURPLE(new Color(0x8932b8), new Color(0xa020f0), new Color(0x7b2fbe), 24),
BLUE(new Color(0x3c44aa), new Color(0xff), new Color(0x253192), 25),
BROWN(new Color(0x835432), new Color(0x8b4513), new Color(0x51301a), 26),
GREEN(new Color(0x5e7c16), new Color(0xff00), new Color(0x3b511a), 27),
RED(new Color(0xb02e26), new Color(0xff0000), new Color(0xb3312c), 28),
BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29);
private final Color textureDiffuseColor;
private final Color textColor;
private final Color fireworkColor;
private final int mapColorId;
DyeColor(@NotNull Color textureDiffuseColor, @NotNull Color textColor,
@NotNull Color fireworkColor, int mapColorId) {
this.textureDiffuseColor = textureDiffuseColor;
this.textColor = textColor;
this.fireworkColor = fireworkColor;
this.mapColorId = mapColorId;
}
public @NotNull Color color() {
return this.textureDiffuseColor;
}
public @NotNull Color textColor() {
return this.textColor;
}
public @NotNull Color fireworkColor() {
return this.fireworkColor;
}
@Override
public int red() {
return this.textureDiffuseColor.red();
}
@Override
public int green() {
return this.textureDiffuseColor.green();
}
@Override
public int blue() {
return this.textureDiffuseColor.blue();
}
public int mapColorId() {
return this.mapColorId;
}
}

View file

@ -0,0 +1,38 @@
package me.tofaa.entitylib.extras;
public enum Rotation {
/**
* No rotation
*/
NONE,
/**
* Rotated clockwise by 45 degrees
*/
CLOCKWISE_45,
/**
* Rotated clockwise by 90 degrees
*/
CLOCKWISE,
/**
* Rotated clockwise by 135 degrees
*/
CLOCKWISE_135,
/**
* Flipped upside-down, a 180-degree rotation
*/
FLIPPED,
/**
* Flipped upside-down + 45-degree rotation
*/
FLIPPED_45,
/**
* Rotated counter-clockwise by 90 degrees
*/
COUNTER_CLOCKWISE,
/**
* Rotated counter-clockwise by 45 degrees
*/
COUNTER_CLOCKWISE_45;
}

View file

@ -1,11 +1,10 @@
package me.tofaa.entitylib.meta.mobs.tameable; package me.tofaa.entitylib.meta.mobs.tameable;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import me.tofaa.entitylib.extras.DyeColor; import me.tofaa.entitylib.extras.DyeColor;
import me.tofaa.entitylib.meta.Metadata; import me.tofaa.entitylib.meta.Metadata;
import me.tofaa.entitylib.meta.types.TameableMeta; import me.tofaa.entitylib.meta.types.TameableMeta;
import net.kyori.adventure.text.format.NamedTextColor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CatMeta extends TameableMeta { public class CatMeta extends TameableMeta {

View file

@ -9,11 +9,11 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* Represents a storage/container for {@link Tickable}s. * Represents a storage/container for {@link Tickable}s. This class is extendable in case you want to provide custom logic and/or methods.
* @param <T> The type of {@link Tickable} to store. * @param <T> The type of {@link Tickable} to store.
* @param <H> If a platform enforces a specific method of ticking, this type represents the handler for that method. * @param <H> If a platform enforces a specific method of ticking, this type represents the handler for that method.
*/ */
public abstract class TickContainer<T extends Tickable, H> { public class TickContainer<T extends Tickable, H> {
private final Set<T> tickables = new HashSet<>(); private final Set<T> tickables = new HashSet<>();
private H handle; private H handle;

View file

@ -32,7 +32,7 @@ public class WrapperEntityCreature extends WrapperLivingEntity {
@Override @Override
public void tick(long time) { public void tick(long time) {
super.tick(time); super.tick(time);
aiGroups.forEach(aiGroup -> aiGroup.update(time)); aiGroups.forEach(aiGroup -> aiGroup.tick(time));
} }
/** /**

View file

@ -11,6 +11,7 @@ public class AIGroup implements Tickable {
private final List<GoalSelector> goalSelectors = new GoalSelectorList(this); private final List<GoalSelector> goalSelectors = new GoalSelectorList(this);
private GoalSelector currentGoalSelector; private GoalSelector currentGoalSelector;
private boolean ticking = true;
public @NotNull Collection<GoalSelector> getGoalSelectors() { public @NotNull Collection<GoalSelector> getGoalSelectors() {
return goalSelectors; return goalSelectors;
@ -36,6 +37,16 @@ public class AIGroup implements Tickable {
currentGoalSelector = goalSelector; currentGoalSelector = goalSelector;
} }
@Override
public boolean isTicking() {
return ticking;
}
@Override
public void setTicking(boolean ticking) {
this.ticking = ticking;
}
@Override @Override
public void tick(long time) { public void tick(long time) {
GoalSelector currentGoalSelector = getCurrentGoal(); GoalSelector currentGoalSelector = getCurrentGoal();

View file

@ -31,7 +31,7 @@ public abstract class AbstractWorldWrapper<W> implements WorldWrapper<W> {
this.handle = handle; this.handle = handle;
this.dimension = dimension; this.dimension = dimension;
this.entities = new ConcurrentHashMap<>(); this.entities = new ConcurrentHashMap<>();
this.entitiesById = Collections.emptyMap(); this.entitiesById = new ConcurrentHashMap<>();
} }

View file

@ -32,6 +32,6 @@ dependencies {
tasks { tasks {
runServer { runServer {
minecraftVersion("1.19.4") minecraftVersion("1.20.4")
} }
} }

View file

@ -1,7 +1,6 @@
package me.tofaa.testentitylib; package me.tofaa.testentitylib;
import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import io.github.retrooper.packetevents.util.SpigotConversionUtil; import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import me.tofaa.entitylib.APIConfig; import me.tofaa.entitylib.APIConfig;
@ -43,15 +42,17 @@ public class TestEntityLibPlugin extends JavaPlugin implements Listener {
@EventHandler @EventHandler
public void onCrouch(PlayerToggleSneakEvent event) { public void onCrouch(PlayerToggleSneakEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (e != null) { if (e == null) {
e.remove(); world = api.wrapWorld(player.getWorld());
e = null; e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
} }
world = api.wrapWorld(player.getWorld()); world = api.wrapWorld(player.getWorld());
e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation())); e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
ChickenMeta meta = (ChickenMeta) e.getEntityMeta(); ChickenMeta meta = (ChickenMeta) e.getEntityMeta();
meta.setBaby(!meta.isBaby()); meta.setBaby(!meta.isBaby());
meta.setHasGlowingEffect(!meta.hasGlowingEffect()); meta.setHasGlowingEffect(!meta.hasGlowingEffect());
e.addViewer(player.getUniqueId());
} }
} }