Skip to content

Commit 4f22324

Browse files
committed
allow overriding controller recipes, correctly determine atlas size for lava rendering, correctly register custom forges with the Fluid API (fixes Noaaan/MythicMetals#86)
1 parent c022594 commit 4f22324

File tree

8 files changed

+58
-13
lines changed

8 files changed

+58
-13
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ minecraft_version=1.19
77
yarn_mappings=1.19+build.1
88
loader_version=0.14.7
99
# Mod Properties
10-
mod_version=2.0.14
10+
mod_version=2.0.15
1111
maven_group=wraith
1212
archives_base_name=wraith-alloy-forgery
1313

src/main/java/wraith/alloyforgery/AlloyForgery.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import io.wispforest.owo.particles.systems.ParticleSystemController;
88
import net.fabricmc.api.ModInitializer;
99
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
10-
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
11-
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
1210
import net.minecraft.block.entity.BlockEntityType;
1311
import net.minecraft.particle.ParticleTypes;
1412
import net.minecraft.resource.ResourceType;
@@ -29,7 +27,7 @@ public class AlloyForgery implements ModInitializer {
2927

3028
public static final OwoItemGroup ALLOY_FORGERY_GROUP = new AlloyForgeryItemGroup(id("alloy_forgery"));
3129

32-
public static BlockEntityType<ForgeControllerBlockEntity> FORGE_CONTROLLER_BLOCK_ENTITY;
30+
public static BlockEntityType<ForgeControllerBlockEntity> FORGE_CONTROLLER_BLOCK_ENTITY = ForgeControllerBlockEntity.Type.INSTANCE;
3331
public static ScreenHandlerType<AlloyForgeScreenHandler> ALLOY_FORGE_SCREEN_HANDLER_TYPE;
3432

3533
private static final ParticleSystemController CONTROLLER = new ParticleSystemController(id("particles"));
@@ -47,17 +45,13 @@ public class AlloyForgery implements ModInitializer {
4745
});
4846

4947
@Override
50-
@SuppressWarnings("UnstableApiUsage")
5148
public void onInitialize() {
52-
ALLOY_FORGE_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(id("alloy_forge"), AlloyForgeScreenHandler::new);
49+
ALLOY_FORGE_SCREEN_HANDLER_TYPE = Registry.register(Registry.SCREEN_HANDLER, id("alloy_forge"), new ScreenHandlerType<>(AlloyForgeScreenHandler::new));
5350

5451
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(FuelDataLoader.INSTANCE);
55-
5652
ModDataLoader.load(ForgeRegistry.Loader.INSTANCE);
57-
FORGE_CONTROLLER_BLOCK_ENTITY = ForgeControllerBlockEntity.Type.INSTANCE;
5853

5954
Registry.register(Registry.BLOCK_ENTITY_TYPE, id("forge_controller"), FORGE_CONTROLLER_BLOCK_ENTITY);
60-
FluidStorage.SIDED.registerSelf(FORGE_CONTROLLER_BLOCK_ENTITY);
6155

6256
Registry.register(Registry.RECIPE_TYPE, AlloyForgeRecipe.Type.ID, AlloyForgeRecipe.Type.INSTANCE);
6357
Registry.register(Registry.RECIPE_SERIALIZER, AlloyForgeRecipe.Type.ID, AlloyForgeRecipeSerializer.INSTANCE);

src/main/java/wraith/alloyforgery/client/AlloyForgeScreen.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
public class AlloyForgeScreen extends HandledScreen<AlloyForgeScreenHandler> {
1515

16+
public static int blockAtlasWidth = 0, blockAtlasHeight = 0;
17+
1618
private static final Identifier TEXTURE = AlloyForgery.id("textures/gui/forge_controller.png");
1719
private final SpriteIdentifier lavaSpriteId = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier("block/lava_still"));
1820

@@ -45,11 +47,11 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
4547
final var fullFrames = this.handler.getLavaProgress() / 16;
4648
for (int i = 0; i < fullFrames; i++) {
4749
drawTexture(matrices, this.x + 63 + i * 16, this.y + 4, lavaSprite.getX(), lavaSprite.getY() + 2,
48-
16, 10, 1024, 1024);
50+
16, 10, blockAtlasWidth, blockAtlasHeight);
4951
}
5052

5153
drawTexture(matrices, this.x + 63 + fullFrames * 16, this.y + 4, lavaSprite.getX(), lavaSprite.getY() + 2,
52-
(this.handler.getLavaProgress() - fullFrames * 16), 10, 1024, 1024);
54+
(this.handler.getLavaProgress() - fullFrames * 16), 10, blockAtlasWidth, blockAtlasHeight);
5355
}
5456

5557
public int rootX() {

src/main/java/wraith/alloyforgery/forges/ForgeDefinition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import com.google.gson.JsonObject;
77
import io.wispforest.owo.registration.ComplexRegistryAction;
88
import io.wispforest.owo.registration.RegistryHelper;
9+
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
910
import net.minecraft.block.Block;
1011
import net.minecraft.util.Identifier;
1112
import net.minecraft.util.JsonHelper;
1213
import net.minecraft.util.registry.Registry;
14+
import wraith.alloyforgery.AlloyForgery;
1315

1416
import java.util.ArrayList;
1517

@@ -50,6 +52,7 @@ private ForgeDefinition(int forgeTier, float speedMultiplier, int fuelCapacity,
5052
this(forgeTier, speedMultiplier, fuelCapacity, (int) (BASE_MAX_SMELT_TIME / speedMultiplier), material, additionalMaterials);
5153
}
5254

55+
@SuppressWarnings("UnstableApiUsage")
5356
public static void loadAndEnqueue(Identifier id, JsonObject json) {
5457

5558
final int forgeTier = JsonHelper.getInt(json, "tier");
@@ -69,6 +72,7 @@ public static void loadAndEnqueue(Identifier id, JsonObject json) {
6972
final var definition = new ForgeDefinition(forgeTier, speedMultiplier, fuelCapacity, mainMaterial, additionalMaterialsBuilder.build());
7073

7174
ForgeRegistry.registerDefinition(id, definition);
75+
FluidStorage.SIDED.registerSelf(AlloyForgery.FORGE_CONTROLLER_BLOCK_ENTITY);
7276

7377
}).entry(mainMaterialId).entries(additionalMaterialIds).build();
7478

src/main/java/wraith/alloyforgery/mixin/RecipeManagerMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class RecipeManagerMixin {
2020
public void injectForgeRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
2121
for (var id : ForgeRegistry.getForgeIds()) {
2222
final var forgeDefinition = ForgeRegistry.getForgeDefinition(id).get();
23-
map.put(id, forgeDefinition.generateRecipe(id));
23+
map.putIfAbsent(id, forgeDefinition.generateRecipe(id));
2424
}
2525
}
2626

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package wraith.alloyforgery.mixin;
2+
3+
import net.minecraft.client.texture.SpriteAtlasTexture;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(SpriteAtlasTexture.Data.class)
8+
public interface SpriteAtlasTextureDataAccessor {
9+
@Accessor("width")
10+
int af$getWidth();
11+
12+
@Accessor("height")
13+
int af$getHeight();
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package wraith.alloyforgery.mixin;
2+
3+
import net.minecraft.client.texture.SpriteAtlasTexture;
4+
import net.minecraft.screen.PlayerScreenHandler;
5+
import net.minecraft.util.Identifier;
6+
import org.spongepowered.asm.mixin.Final;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
import wraith.alloyforgery.client.AlloyForgeScreen;
13+
14+
@Mixin(SpriteAtlasTexture.class)
15+
public class SpriteAtlasTextureMixin {
16+
17+
@Shadow
18+
@Final
19+
private Identifier id;
20+
21+
@Inject(method = "upload", at = @At("HEAD"))
22+
private void captureSize(SpriteAtlasTexture.Data data, CallbackInfo ci) {
23+
if (!this.id.equals(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE)) return;
24+
25+
AlloyForgeScreen.blockAtlasWidth = ((SpriteAtlasTextureDataAccessor) data).af$getWidth();
26+
AlloyForgeScreen.blockAtlasHeight = ((SpriteAtlasTextureDataAccessor) data).af$getHeight();
27+
}
28+
29+
}

src/main/resources/alloy-forgery.mixins.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"DefaultedRegistryMixin",
99
"HopperBlockEntityMixin",
1010
"HopperHelperMixin",
11-
"RecipeManagerMixin"
11+
"RecipeManagerMixin",
12+
"SpriteAtlasTextureDataAccessor"
1213
],
1314
"client": [
15+
"SpriteAtlasTextureMixin"
1416
],
1517
"injectors": {
1618
"defaultRequire": 1

0 commit comments

Comments
 (0)