Skip to content

Commit

Permalink
Merge pull request #15 from ZZZank/fixing
Browse files Browse the repository at this point in the history
Fixing
  • Loading branch information
ZZZank authored Nov 25, 2024
2 parents 2be1fa6 + 30cb4c0 commit 861f8db
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 168 deletions.
21 changes: 13 additions & 8 deletions common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import dev.latvian.mods.rhino.mod.wrapper.DirectionWrapper;
import dev.latvian.mods.rhino.mod.wrapper.UUIDWrapper;
import dev.latvian.mods.rhino.util.wrap.TypeWrappers;
import lombok.val;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.registry.ToolType;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -182,7 +183,7 @@ public void initStartup() {
new ItemToolTierEventJS().post(KubeJSEvents.ITEM_REGISTRY_TOOL_TIERS);
new ItemArmorTierEventJS().post(KubeJSEvents.ITEM_REGISTRY_ARMOR_TIERS);

for (var registryInfo : RegistryInfos.WITH_TYPE.values()) {
for (val registryInfo : RegistryInfos.WITH_TYPE.values()) {
registryInfo.fireRegistryEvent();
}
// new BlockRegistryEventJS().post(KubeJSEvents.BLOCK_REGISTRY);
Expand Down Expand Up @@ -387,8 +388,12 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
return (BlockPos) o;
} else if (o instanceof BlockContainerJS) {
return ((BlockContainerJS) o).getPos();
} else if (o instanceof List && ((List<?>) o).size() >= 3) {
return new BlockPos(((Number) ((List<?>) o).get(0)).intValue(), ((Number) ((List<?>) o).get(1)).intValue(), ((Number) ((List<?>) o).get(2)).intValue());
} else if (o instanceof List<?> l && l.size() >= 3) {
return new BlockPos(
((Number) l.get(0)).intValue(),
((Number) l.get(1)).intValue(),
((Number) l.get(2)).intValue()
);
}

return BlockPos.ZERO;
Expand All @@ -399,7 +404,7 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
return v;
} else if (o instanceof EntityJS ent) {
return ent.minecraftEntity.position();
} else if (o instanceof List l && l.size() >= 3) {
} else if (o instanceof List<?> l && l.size() >= 3) {
return new Vec3(
((Number) l.get(0)).doubleValue(),
((Number) l.get(1)).doubleValue(),
Expand All @@ -408,7 +413,7 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
} else if (o instanceof BlockPos bp) {
return new Vec3(bp.getX() + 0.5D, bp.getY() + 0.5D, bp.getZ() + 0.5D);
} else if (o instanceof BlockContainerJS container) {
BlockPos bp = container.getPos();
val bp = container.getPos();
return new Vec3(bp.getX() + 0.5D, bp.getY() + 0.5D, bp.getZ() + 0.5D);
}

Expand Down Expand Up @@ -543,14 +548,14 @@ public void addRecipes(RegisterRecipeHandlersEvent event) {

@Override
public void generateDataJsons(DataJsonGenerator generator) {
for (var builder : RegistryInfos.ALL_BUILDERS) {
for (val builder : RegistryInfos.ALL_BUILDERS) {
builder.generateDataJsons(generator);
}
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
for (var builder : RegistryInfos.ALL_BUILDERS) {
for (val builder : RegistryInfos.ALL_BUILDERS) {
builder.generateAssetJsons(generator);
}
}
Expand All @@ -559,7 +564,7 @@ public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateLang(Map<String, String> lang) {
lang.put("itemGroup.kubejs.kubejs", "KubeJS");

for (var builder : RegistryInfos.ALL_BUILDERS) {
for (val builder : RegistryInfos.ALL_BUILDERS) {
if (builder.overrideLangJson && builder.display != null) {
lang.put(builder.getTranslationKey(), builder.display.getString());
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/dev/latvian/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public KubeJS() throws Throwable {
KubeJSPlugins.forEachPlugin(KubeJSPlugin::init);

if (!CommonProperties.get().serverOnly) {
var tabEvent = new CreativeTabRegistryEventJS();
val tabEvent = new CreativeTabRegistryEventJS();
tab = tabEvent.create(KubeJS.MOD_ID, () -> ItemStackJS.of(new ItemStack(Items.PURPLE_DYE)));
tabEvent.post(ScriptType.STARTUP, KubeJSEvents.TAB_REGISTRY);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.latvian.kubejs.bindings;

import dev.latvian.kubejs.KubeJSRegistries;
import dev.latvian.kubejs.block.MaterialJS;
import dev.latvian.kubejs.block.MaterialListJS;
import dev.latvian.kubejs.block.predicate.BlockEntityPredicate;
Expand All @@ -11,7 +10,6 @@
import dev.latvian.mods.rhino.annotations.typing.JSInfo;
import lombok.val;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.block.Block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static Text fromComponent(Component c) {

var style = c.getStyle();
t.bold(style.isBold())
.color(ColorWrapper.of(style.getColor()))
.font(style.getFont())
.italic(style.isItalic())
.underlined(style.isUnderlined())
.strikethrough(style.isStrikethrough())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ private static int reloadStartup(CommandSourceStack source) {
}

private static int reloadServer(CommandSourceStack source) {
ServerScriptManager.instance.reloadScriptManager(((MinecraftServerKJS) source.getServer()).getServerResourcesKJS()
.getResourceManager());
ServerScriptManager.instance.reloadScriptManager(
((MinecraftServerKJS) source.getServer()).getServerResourcesKJS().getResourceManager()
);
UtilsJS.postModificationEvents();
source.sendSuccess(new TextComponent(
"Done! To reload recipes, tags, loot tables and other datapack things, run /reload"), false);
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/dev/latvian/kubejs/core/AsKJS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package dev.latvian.kubejs.core;

public interface AsKJS {
Object asKJS();
public interface AsKJS<T> {
T asKJS();
}
8 changes: 4 additions & 4 deletions common/src/main/java/dev/latvian/kubejs/core/EntityKJS.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package dev.latvian.kubejs.core;

import dev.latvian.kubejs.KubeJS;
import dev.latvian.kubejs.entity.EntityJS;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;

public interface EntityKJS extends AsKJS {
public interface EntityKJS extends AsKJS<EntityJS> {
@Override
default Object asKJS() {
Entity entity = (Entity) this;
return KubeJS.PROXY.getWorld(entity.level).getEntity(entity);
default EntityJS asKJS() {
return KubeJS.PROXY.getWorld(((Entity) this).level).getEntity((Entity) this);
}

CompoundTag getPersistentDataKJS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import dev.latvian.kubejs.item.ingredient.IngredientJS;
import net.minecraft.world.item.ItemStack;

public interface IngredientKJS extends AsKJS {
public interface IngredientKJS extends AsKJS<IngredientJS> {
@Override
default Object asKJS() {
default IngredientJS asKJS() {
return IngredientJS.of(this);
}

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

import dev.latvian.kubejs.item.ItemStackJS;

public interface ItemStackKJS extends AsKJS {
public interface ItemStackKJS extends AsKJS<ItemStackJS> {
@Override
default Object asKJS() {
default ItemStackJS asKJS() {
return ItemStackJS.of(this);
}

Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/dev/latvian/kubejs/core/LevelKJS.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.latvian.kubejs.core;

import dev.latvian.kubejs.KubeJS;
import dev.latvian.kubejs.world.WorldJS;
import net.minecraft.world.level.Level;

public interface LevelKJS extends AsKJS {
public interface LevelKJS extends AsKJS<WorldJS> {
@Override
default Object asKJS() {
default WorldJS asKJS() {
return KubeJS.PROXY.getWorld((Level) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import dev.latvian.kubejs.server.ServerJS;
import net.minecraft.server.ServerResources;

public interface MinecraftServerKJS extends AsKJS {
public interface MinecraftServerKJS extends AsKJS<ServerJS> {
@Override
default Object asKJS() {
default ServerJS asKJS() {
return ServerJS.instance;
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/dev/latvian/kubejs/event/EventJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public final boolean post(@NotNull ScriptType type, @NotNull List<String> ids) {
val e = type.manager.get().events;
boolean cancelled = false;
for (val id : ids) {
cancelled = e.postToHandlers(id, e.handlers(id), this);
if (cancelled) {
break; //prevent posting events after being cancelled
}
cancelled = e.postToHandlers(id, e.handlers(id), this);
}
afterPosted(cancelled);
return cancelled;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.latvian.kubejs.item.ingredient;

import dev.latvian.kubejs.item.ItemStackJS;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand All @@ -12,11 +14,9 @@
/**
* @author LatvianModder
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MatchAllIngredientJS implements IngredientJS {
public static MatchAllIngredientJS INSTANCE = new MatchAllIngredientJS();

private MatchAllIngredientJS() {
}
public static final MatchAllIngredientJS INSTANCE = new MatchAllIngredientJS();

@Override
public boolean test(ItemStackJS stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
@Mixin(Entity.class)
public abstract class EntityMixin implements EntityKJS {
@Unique
private final CompoundTag persistentDataKJS = new CompoundTag();
private final CompoundTag kjs$persistentData = new CompoundTag();

@Override
public CompoundTag getPersistentDataKJS() {
return persistentDataKJS;
return kjs$persistentData;
}

@Inject(method = "saveWithoutId", at = @At("RETURN"))
private void saveKJS(CompoundTag tag, CallbackInfoReturnable<CompoundTag> ci) {
tag.put("KubeJSPersistentData", persistentDataKJS);
tag.put("KubeJSPersistentData", kjs$persistentData);
}

@Inject(method = "load", at = @At("RETURN"))
private void loadKJS(CompoundTag tag, CallbackInfo ci) {
((MapLike<?, ?>) persistentDataKJS).clearML();
persistentDataKJS.merge(tag.getCompound("KubeJSPersistentData"));
((MapLike<?, ?>) kjs$persistentData).clearML();
kjs$persistentData.merge(tag.getCompound("KubeJSPersistentData"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ private void isFoilKJS(ItemStack itemStack, CallbackInfoReturnable<Boolean> ci)
}
}

@Inject(method = "appendHoverText", at = @At("RETURN"))
private void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flagIn, CallbackInfo ci) {
if (itemBuilderKJS != null && !itemBuilderKJS.tooltip.isEmpty()) {
tooltip.addAll(itemBuilderKJS.tooltip);
}
}

@Inject(method = "getUseDuration", at = @At("HEAD"), cancellable = true)
private void getUseDuration(ItemStack itemStack, CallbackInfoReturnable<Integer> ci) {
if (itemBuilderKJS != null && itemBuilderKJS.useDuration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public RegisterRecipeHandlersEvent(Map<ResourceLocation, RecipeTypeJS> m) {

public void register(RecipeTypeJS type) {
map.put(Registries.getId(type.serializer, Registry.RECIPE_SERIALIZER_REGISTRY), type);
KubeJS.LOGGER.info("Registered custom recipe handler for type " + type);
KubeJS.LOGGER.info("Registered custom recipe handler for type {}", type);
}

public void register(ResourceLocation id, Supplier<RecipeJS> f) {
Expand Down
9 changes: 7 additions & 2 deletions common/src/main/java/dev/latvian/kubejs/text/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,14 @@ public final Text insertion(@Nullable String value) {
return this;
}

public final Text font(ResourceLocation rl) {
font = rl;
return this;
}

@HideFromJS
public final Text font(@Nullable String value) {
font = value == null || value.isEmpty() ? null : new ResourceLocation(value);
return this;
return font(value == null || value.isEmpty() ? null : new ResourceLocation(value));
}

public final Text click(@Nullable Object o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package dev.latvian.kubejs.util;

import lombok.Getter;

import java.util.HashMap;

/**
* @author LatvianModder
*/
@Getter
public class AttachedData extends HashMap<String, Object> {
private final Object parent;

public AttachedData(Object p) {
parent = p;
}

public Object getParent() {
return parent;
}
}
Loading

0 comments on commit 861f8db

Please sign in to comment.