Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2002' into 2004
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java
  • Loading branch information
MaxNeedsSnacks committed Jan 30, 2024
2 parents 395bb59 + 5aa597b commit 78ac287
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/latvian/mods/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void loadComplete() {
.followRedirects(HttpClient.Redirect.ALWAYS)
.connectTimeout(Duration.ofSeconds(5L))
.build()
.send(HttpRequest.newBuilder().uri(URI.create("https://kubejs.com/update-check?" + QUERY)).GET().build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
.send(HttpRequest.newBuilder().uri(URI.create("https://v.kubejs.com/update-check?" + QUERY)).GET().build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
if (response.statusCode() == 200) {
var body = response.body().trim();

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/bindings/UtilsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

Expand Down Expand Up @@ -244,4 +246,12 @@ static ParticleOptions particleOptions(Object o) {

return ERROR_PARTICLE;
}

@Info("Parses a block state from the input string. May throw for invalid inputs!")
static BlockState parseBlockState(Object o) {
if (o instanceof BlockState bs) {
return bs;
}
return o == null ? Blocks.AIR.defaultBlockState() : UtilsJS.parseBlockState(o.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -157,4 +158,8 @@ private void loadKJS(CompoundTag tag, CallbackInfo ci) {
@Shadow
@RemapForJS("distanceToEntity")
public abstract float distanceTo(Entity arg);

@Shadow
@HideFromJS
public abstract Level level();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

@Info("""
Invoked before an entity is spawned into the world.
Expand All @@ -19,9 +20,11 @@ public class CheckLivingEntitySpawnEventJS extends LivingEntityEventJS {

public final double x, y, z;
public final MobSpawnType type;

@Nullable
public final BaseSpawner spawner;

public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type, @Nullable BaseSpawner spawner) {
this.entity = entity;
this.level = level;
this.x = x;
Expand Down Expand Up @@ -53,7 +56,8 @@ public MobSpawnType getType() {
return type;
}

@Info("The spawner that spawned the entity.")
@Info("The spawner that spawned the entity. Can be null if the entity was spawned by worldgen.")
@Nullable
public BaseSpawner getSpawner() {
return spawner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import org.jetbrains.annotations.Nullable;

public class KubeJSEntityEventHandler {
public static void init() {
Expand All @@ -20,7 +21,7 @@ public static void init() {
EntityEvent.ADD.register(KubeJSEntityEventHandler::entitySpawned);
}

private static EventResult checkSpawn(LivingEntity entity, LevelAccessor la, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
private static EventResult checkSpawn(LivingEntity entity, LevelAccessor la, double x, double y, double z, MobSpawnType type, @Nullable BaseSpawner spawner) {
if (la instanceof Level level && (la.isClientSide() || UtilsJS.staticServer != null) && EntityEvents.CHECK_SPAWN.hasListeners()) {
return EntityEvents.CHECK_SPAWN.post(level, entity.getType(), new CheckLivingEntitySpawnEventJS(entity, level, x, y, z, type, spawner)).arch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ public RecipeExceptionJS(String m, Throwable cause) {

@Override
public String toString() {
return getLocalizedMessage();
var sb = new StringBuilder();
sb.append(getMessage());
if (error) {
sb.append(" [error]");
}

// append cause as well since RecipeExceptions can swallow underlying problems
if (getCause() != null) {
sb.append("\ncause: ");
sb.append(getCause());
}

return sb.toString();
}

public RecipeExceptionJS error() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,13 @@ public void post(RecipeManager recipeManager, Map<ResourceLocation, JsonElement>
private RecipeHolder<?> createRecipe(RecipeJS r) {
try {
var rec = r.createRecipe();
var path = r.kjs$getMod() + "/" + r.getPath();

if (DataExport.export != null) {
DataExport.export.addJson("recipes/" + rec.id() + ".json", r.json);
if (!r.removed && DataExport.export != null) {
DataExport.export.addJson("recipes/%s.json".formatted(path), r.json);

if (r.newRecipe) {
DataExport.export.addJson("added_recipes/" + rec.id() + ".json", r.json);
DataExport.export.addJson("added_recipes/%s.json".formatted(path), r.json);
}
}

Expand Down

0 comments on commit 78ac287

Please sign in to comment.