Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.spatial.SpatialResource;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.server.core.entity.Entity;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.server.core.modules.entity.item.ItemComponent;
Expand Down Expand Up @@ -44,6 +45,16 @@ public static ReferenceType<?> getType(Class<? extends Component<?>> componentCl
return TYPES_MAP.get(componentClass);
}

@SuppressWarnings("unchecked")
public static @Nullable Ref<EntityStore> getRef(Object o) {
if (o instanceof Ref<?> ref) {
return (Ref<EntityStore>) ref;
} else if (o instanceof Entity entity) {
return entity.getReference();
}
return null;
}

public static List<Ref<EntityStore>> getRefsInSphere(@Nonnull Vector3d pos, double radius, @Nonnull Store<EntityStore> store) {
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
EntityModule entityModule = EntityModule.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,30 @@
import com.hypixel.hytale.math.vector.Location;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
import com.hypixel.hytale.server.core.asset.type.model.config.Model;
import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
import com.hypixel.hytale.server.core.entity.Entity;
import com.hypixel.hytale.server.core.entity.LivingEntity;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.server.core.entity.entities.BlockEntity;
import com.hypixel.hytale.server.core.entity.movement.MovementStatesComponent;
import com.hypixel.hytale.server.core.entity.nameplate.Nameplate;
import com.hypixel.hytale.server.core.inventory.ItemStack;
import com.hypixel.hytale.server.core.modules.entity.component.EntityScaleComponent;
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
import com.hypixel.hytale.server.core.modules.entity.component.PersistentModel;
import com.hypixel.hytale.server.core.modules.entity.component.PropComponent;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.item.ItemComponent;
import com.hypixel.hytale.server.core.modules.entity.item.PreventItemMerging;
import com.hypixel.hytale.server.core.modules.entity.item.PreventPickup;
import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatMap;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatsModule;
import com.hypixel.hytale.server.core.universe.Universe;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
Expand All @@ -29,6 +44,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import java.util.UUID;

/**
Expand Down Expand Up @@ -227,7 +243,7 @@ public static <ECS, T extends Component<ECS>> void tryRemoveComponent(Entity ent

@SuppressWarnings({"DataFlowIssue"})
public static @NotNull Pair<Ref<EntityStore>, ItemComponent> dropItem(Store<EntityStore> store, ItemStack itemStack,
Location location, Vector3f velocity, float pickupDelay) {
Location location, Vector3f velocity, float pickupDelay) {
if (itemStack.isEmpty() || !itemStack.isValid()) {
return new Pair<>(null, null);
}
Expand Down Expand Up @@ -324,4 +340,119 @@ public static void clearMarkedEntity(NPCEntity npcEntity, @Nullable Entity targe
}
}

private static String getItemModelId(@Nonnull Item item) {
String modelId = item.getModel();

if (modelId == null && item.hasBlockType()) {
BlockType blockType = BlockType.getAssetMap().getAsset(item.getId());

if (blockType != null && blockType.getCustomModel() != null) {
modelId = blockType.getCustomModel();
}
}

return modelId;
}

private static Model getItemModel(@Nonnull Item item) {
String modelId = getItemModelId(item);

if (modelId == null) {
return null;
} else {
ModelAsset modelAsset = ModelAsset.getAssetMap().getAsset(modelId);

return modelAsset != null ? Model.createStaticScaledModel(modelAsset, 1.0f) : null;
}
}

public static Ref<EntityStore> spawnModel(@NotNull Object object, @NotNull Location location) {
return switch (object) {
case Item item -> spawnItem(item, location);
case BlockType blockType -> spawnBlock(null, blockType, location);
case ModelAsset modelAsset -> spawnModel(null, Model.createStaticScaledModel(modelAsset, 1.0f), location);
default -> null;
};
}

public static Ref<EntityStore> spawnModel(@Nullable Item item, @NotNull Model model, @NotNull Location location) {
World world = Universe.get().getWorld(location.getWorld());
if (world == null) return null;

Store<EntityStore> store = world.getEntityStore().getStore();
Holder<EntityStore> holder = store.getRegistry().newHolder();

holder.addComponent(NetworkId.getComponentType(), new NetworkId(store.getExternalData().takeNextNetworkId()));
holder.addComponent(TransformComponent.getComponentType(), new TransformComponent(location.getPosition(), location.getRotation()));
holder.addComponent(ModelComponent.getComponentType(), new ModelComponent(model));
holder.addComponent(PersistentModel.getComponentType(),
new PersistentModel(
new Model.ModelReference(model.getModelAssetId(), 1.0f, null, true)));
if (item != null) {
ItemStack itemStack = new ItemStack(item.getId(), 1);
itemStack.setOverrideDroppedItemAnimation(true);
holder.addComponent(ItemComponent.getComponentType(), new ItemComponent(itemStack));
}
holder.addComponent(EntityScaleComponent.getComponentType(), new EntityScaleComponent(1.0f));
holder.addComponent(PreventPickup.getComponentType(), PreventPickup.INSTANCE);
holder.addComponent(PreventItemMerging.getComponentType(), PreventItemMerging.INSTANCE);
holder.addComponent(HeadRotation.getComponentType(), new HeadRotation(location.getRotation()));
holder.addComponent(PropComponent.getComponentType(), PropComponent.get());
holder.ensureComponent(UUIDComponent.getComponentType());
return store.addEntity(holder, AddReason.SPAWN);
}

public static Ref<EntityStore> spawnItem(@NotNull Item item, @NotNull Location location) {
Model model = getItemModel(item);
if (model != null) {
return spawnModel(item, model, location);
}
if (item.hasBlockType()) {
BlockType blockType = BlockType.getAssetMap().getAsset(item.getId());
if (blockType != null) {
return spawnBlock(item, blockType, location);
}
}
World world = Universe.get().getWorld(location.getWorld());
if (world == null) return null;

Store<EntityStore> store = world.getEntityStore().getStore();
Holder<EntityStore> holder = store.getRegistry().newHolder();

holder.addComponent(NetworkId.getComponentType(), new NetworkId(store.getExternalData().takeNextNetworkId()));
holder.addComponent(TransformComponent.getComponentType(), new TransformComponent(location.getPosition(), location.getRotation()));
ItemStack itemStack = new ItemStack(item.getId(), 1);
itemStack.setOverrideDroppedItemAnimation(true);
holder.addComponent(ItemComponent.getComponentType(), new ItemComponent(itemStack));
holder.addComponent(EntityScaleComponent.getComponentType(), new EntityScaleComponent(1.0f));
holder.addComponent(PreventPickup.getComponentType(), PreventPickup.INSTANCE);
holder.addComponent(PreventItemMerging.getComponentType(), PreventItemMerging.INSTANCE);
holder.addComponent(HeadRotation.getComponentType(), new HeadRotation(location.getRotation()));
holder.addComponent(PropComponent.getComponentType(), PropComponent.get());
return store.addEntity(holder, AddReason.SPAWN);
}

public static Ref<EntityStore> spawnBlock(@Nullable Item item, @NotNull BlockType blockType, @NotNull Location location) {
World world = Universe.get().getWorld(location.getWorld());
if (world == null) return null;

Store<EntityStore> store = world.getEntityStore().getStore();
Holder<EntityStore> holder = store.getRegistry().newHolder();

holder.addComponent(BlockEntity.getComponentType(), new BlockEntity(blockType.getId()));
holder.addComponent(TransformComponent.getComponentType(), new TransformComponent(location.getPosition(), location.getRotation()));
holder.addComponent(EntityScaleComponent.getComponentType(), new EntityScaleComponent(1.0F));
if (item != null) {
ItemStack itemStack = new ItemStack(item.getId(), 1);
itemStack.setOverrideDroppedItemAnimation(true);
holder.addComponent(ItemComponent.getComponentType(), new ItemComponent(itemStack));
}
holder.addComponent(PreventPickup.getComponentType(), PreventPickup.INSTANCE);
holder.addComponent(PreventItemMerging.getComponentType(), PreventItemMerging.INSTANCE);
holder.addComponent(HeadRotation.getComponentType(), new HeadRotation(location.getRotation()));
holder.addComponent(PropComponent.getComponentType(), PropComponent.get());
holder.ensureComponent(UUIDComponent.getComponentType());
return store.addEntity(holder, AddReason.SPAWN);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class JsonDocPrinter {
private final SkriptAddon addon;
private final String addonKey;
private final boolean includeSkriptParser;
private final List<String> ids = new ArrayList<>();

public JsonDocPrinter(CommandSender sender, SkriptAddon addon) {
this.sender = sender;
Expand Down Expand Up @@ -593,7 +594,12 @@ private BsonString getId(String type, String syntaxId) {
addonName = "HySkript";
}
String s = type + ":" + addonName + ":" + syntaxId;
return new BsonString(s.toLowerCase(Locale.ROOT).replace(" ", "_"));
String id = s.toLowerCase(Locale.ROOT).replace(" ", "_");
if (this.ids.contains(id)) {
Utils.error("Duplicate ID: " + id);
}
this.ids.add(id);
return new BsonString(id);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.hypixel.hytale.server.core.modules.accesscontrol.AccessControlModule;
import com.hypixel.hytale.server.core.modules.accesscontrol.provider.HytaleBanProvider;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.WorldConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -37,4 +40,28 @@ public static void init() {
return BAN_PROVIDER;
}

/**
* Set world override time durations of a world.
* <br>I didn't want to do this, but Hytale doesn't have a setter and this is private.
*
* @param world World to change times for
* @param seconds Seconds to override
* @param day Whether to override daytime or nighttime duration
*/
public static void setWorldTimeOverrides(@NotNull World world, @Nullable Integer seconds, boolean day) {
WorldConfig worldConfig = world.getWorldConfig();
try {
Field field;
if (day) {
field = worldConfig.getClass().getDeclaredField("daytimeDurationSecondsOverride");
} else {
field = worldConfig.getClass().getDeclaredField("nighttimeDurationSecondsOverride");
}
field.setAccessible(true);
field.set(worldConfig, seconds);
} catch (NoSuchFieldException | IllegalAccessException ignore) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github.skriptdev.skript.plugin.elements.conditions.player.CondPlayerMovementSprinting;
import com.github.skriptdev.skript.plugin.elements.conditions.player.CondPlayerMovementSwimming;
import com.github.skriptdev.skript.plugin.elements.conditions.player.CondPlayerMovementWalking;
import com.github.skriptdev.skript.plugin.elements.conditions.ref.CondCanBePickedUp;
import com.github.skriptdev.skript.plugin.elements.conditions.world.CondChunkIsLoaded;
import com.github.skriptdev.skript.plugin.elements.conditions.world.CondWorldTimePaused;

Expand Down Expand Up @@ -66,6 +67,9 @@ public static void register(SkriptRegistration registration) {
CondPlayerMovementSwimming.register(registration);
CondPlayerMovementWalking.register(registration);

// REF
CondCanBePickedUp.register(registration);

// WORLD
CondChunkIsLoaded.register(registration);
CondWorldTimePaused.register(registration);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.github.skriptdev.skript.plugin.elements.conditions.ref;

import com.github.skriptdev.skript.api.skript.registration.SkriptRegistration;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.modules.entity.item.PreventPickup;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import io.github.syst3ms.skriptparser.lang.TriggerContext;
import io.github.syst3ms.skriptparser.lang.properties.ConditionalType;
import io.github.syst3ms.skriptparser.lang.properties.PropertyConditional;
import io.github.syst3ms.skriptparser.types.changers.ChangeMode;
import io.github.syst3ms.skriptparser.util.CollectionUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class CondCanBePickedUp extends PropertyConditional<Ref<EntityStore>> {

public static void register(SkriptRegistration reg) {
reg.newPropertyConditional(CondCanBePickedUp.class,
"refs", ConditionalType.CAN, "be picked up")
.name("Ref - Can Be Picked Up")
.description("Check if a ref can be picked up.",
"This generally refers to dropped items.",
"This can be set, preventing items from being picked up.")
.since("INSERT VERSION")
.register();
}

@Override
public boolean check(@NotNull TriggerContext ctx) {
return getPerformer().check(ctx, ref -> {
Store<EntityStore> store = ref.getStore();
return store.getComponent(ref, PreventPickup.getComponentType()) == null;
}, isNegated());
}

@Override
public Optional<Class<?>[]> acceptsChange(@NotNull ChangeMode mode) {
if (mode == ChangeMode.SET) {
return CollectionUtils.optionalArrayOf(Boolean.class);
}
return Optional.empty();
}

@SuppressWarnings("ConstantValue")
@Override
public void change(@NotNull TriggerContext ctx, @NotNull ChangeMode changeMode, Object @NotNull [] changeWith) {
if (changeWith == null || changeWith.length == 0 || !(changeWith[0] instanceof Boolean bool)) {
return;
}
for (Ref<EntityStore> ref : getPerformer().getArray(ctx)) {
Store<EntityStore> store = ref.getStore();
if (bool) {
store.removeComponentIfExists(ref, PreventPickup.getComponentType());
} else {
store.ensureComponent(ref, PreventPickup.getComponentType());
}
}
}

@Override
public String toString(@NotNull TriggerContext ctx, boolean debug) {
return getPerformer().toString(ctx, debug) + " can be picked up";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffFreeze;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffInteraction;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffKill;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffPlayAnimation;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffRemoveStatModifier;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffRide;
import com.github.skriptdev.skript.plugin.elements.effects.entity.EffShoot;
Expand Down Expand Up @@ -56,6 +57,7 @@ public static void register(SkriptRegistration registration) {
EffFreeze.register(registration);
EffInteraction.register(registration);
EffKill.register(registration);
EffPlayAnimation.register(registration);
EffRemoveStatModifier.register(registration);
EffRide.register(registration);
EffShoot.register(registration);
Expand Down
Loading
Loading