Skip to content

Commit

Permalink
Fix loot pool mixin and others (we can load into worlds now)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Feb 27, 2024
1 parent 5ee4b67 commit cc0081c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
package io.github.fabricators_of_create.porting_lib.event.client;

import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;

@Environment(EnvType.CLIENT)
public interface OverlayRenderCallback {
ResourceLocation GUI_ICONS_LOCATION = new ResourceLocation("textures/gui/icons.png");

Event<OverlayRenderCallback> EVENT = EventFactory.createArrayBacked(OverlayRenderCallback.class, callbacks -> (guiGraphics, partialTicks, window, type) -> {
for (OverlayRenderCallback callback : callbacks) {
if (callback.onOverlayRender(guiGraphics, partialTicks, window, type)) {
resetTexture();
return true;
}
}
resetTexture();
return false;
});

private static void resetTexture() { // in case overlays change it, which is very likely.
RenderSystem.setShaderTexture(0, GUI_ICONS_LOCATION);
}

boolean onOverlayRender(GuiGraphics guiGraphics, float partialTicks, Window window, Types type);

enum Types {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class LevelRendererMixin {
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;getRenderableBlockEntities()Ljava/util/List;"
target = "Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$CompiledSection;getRenderableBlockEntities()Ljava/util/List;"
),
to = @At(
value = "INVOKE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.fabricators_of_create.porting_lib.mixin.common;

import com.llamalad7.mixinextras.sugar.Local;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -98,10 +100,10 @@ public abstract class ServerPlayerGameModeMixin {
}

@Inject(method = "destroyBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;playerDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.BY, by = 2), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void port_lib$popXp(BlockPos pos, CallbackInfoReturnable<Boolean> cir, BlockState blockState, BlockEntity blockEntity, Block block, boolean bl) {
private void port_lib$popXp(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local(index = 8) boolean flag) {
int exp = XP.get();
if (bl && exp > 0)
((BlockAccessor)blockState.getBlock()).port_lib$popExperience(level, pos, exp);
if (flag && exp > 0)
((BlockAccessor)this.level.getBlockState(pos).getBlock()).port_lib$popExperience(level, pos, exp);
XP.remove();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import java.util.Optional;

@Mixin(LootPool.class)
public class LootPoolMixin implements LootPoolExtensions {
@Unique
Expand All @@ -38,14 +40,13 @@ public void setName(String name) {
)
private static Codec<LootPool> modifyCodec(Codec<LootPool> original) {
// TODO: test this
return Codec.pair(original, Codec.STRING).xmap(pair -> {
String name = pair.getSecond();
return Codec.pair(original, Codec.STRING.optionalFieldOf("name").codec()).xmap(pair -> {
LootPool pool = pair.getFirst();
pool.setName(name);
pool.setName(pair.getSecond().filter(name -> !name.startsWith("custom#")).orElse(null));
return pool;
}, pool -> {
String name = pool.getName();
return Pair.of(pool, name);
return Pair.of(pool, Optional.ofNullable(name));
});
}

Expand Down

0 comments on commit cc0081c

Please sign in to comment.