9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-29 11:59:11 +00:00

Improved Head Rotate & Fix 1.20.1 NPC Not Spawning & Minor Improvements

This commit is contained in:
iqtester
2025-06-24 02:43:18 -04:00
parent 94e73c1a48
commit 63efa3fd5e
19 changed files with 318 additions and 283 deletions

View File

@@ -4,7 +4,7 @@ import org.joml.Vector3f;
import java.util.Objects;
public abstract class AbstractSeat implements Seat{
public abstract class AbstractSeat implements Seat {
protected final Vector3f offset;
protected final float yaw;

View File

@@ -1,6 +1,5 @@
package net.momirealms.craftengine.core.entity.furniture;
import com.google.common.collect.Lists;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
@@ -9,6 +8,7 @@ import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.ArrayList;
import java.util.List;
public class SeatType {
@@ -23,16 +23,34 @@ public class SeatType {
}
public static Seat fromString(String s) {
List<String> split = Lists.newArrayList(s.split(" "));
int last = split.size() - 1;
int lastSpaceIndex = s.lastIndexOf(' ');
Key type = SIT;
SeatFactory factory;
try {
Float.parseFloat(split.get(last));
} catch (NullPointerException | NumberFormatException e) {
type = Key.withDefaultNamespace(split.get(last), "craftengine");
split.remove(last);
String numericPart;
if (lastSpaceIndex != -1) {
numericPart = s.substring(lastSpaceIndex + 1);
try {
Float.parseFloat(numericPart);
} catch (NumberFormatException e) {
type = Key.withDefaultNamespace(numericPart, "craftengine");
s = s.substring(0, lastSpaceIndex);
lastSpaceIndex = s.lastIndexOf(' ');
}
}
List<String> split = new ArrayList<>();
int start = 0;
while (lastSpaceIndex != -1) {
split.add(s.substring(start, lastSpaceIndex));
start = lastSpaceIndex + 1;
lastSpaceIndex = s.indexOf(' ', start);
}
if (start < s.length()) {
split.add(s.substring(start));
}
factory = BuiltInRegistries.SEAT_FACTORY.getValue(type);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.furniture.seat.invalid_type", type.toString());

View File

@@ -12,10 +12,14 @@ public interface SeatEntity extends EntityPacketHandler {
void dismount(Player player);
void onDismount(Player player);
void event(Player player, Object event);
void destroy();
boolean destroyed();
Furniture furniture();
Vector3f vector3f();

View File

@@ -20,7 +20,7 @@ public interface EntityPacketHandler {
default void handleMove(NetWorkUser user, NMSPacketEvent event, Object packet) {
}
default void handleSetEquipment(NetWorkUser user, NMSPacketEvent event, Object packet) {
default void handleSetEquipment(NetWorkUser user, ByteBufPacketEvent event, Object slots) {
}
default void handleContainerSetSlot(NetWorkUser user, NMSPacketEvent event, Object packet) {

View File

@@ -57,8 +57,6 @@ public class BuiltInRegistries {
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createRegistry(Registries.EVENT_FUNCTION_FACTORY);
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createRegistry(Registries.EVENT_CONDITION_FACTORY);
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createRegistry(Registries.PLAYER_SELECTOR_FACTORY);
public static final Registry<Factory<Function<PlayerBlockActionContext>>> PLAYER_BLOCK_FUNCTION_FACTORY = createRegistry(Registries.PLAYER_BLOCK_FUNCTION_FACTORY);
public static final Registry<Factory<Condition<PlayerBlockActionContext>>> PLAYER_BLOCK_CONDITION_FACTORY = createRegistry(Registries.PLAYER_BLOCK_CONDITION_FACTORY);
public static final Registry<SeatFactory> SEAT_FACTORY = createRegistry(Registries.SEAT_FACTORY);
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {