Skip to content

Commit

Permalink
allow overriding controller recipes, correctly determine atlas size f…
Browse files Browse the repository at this point in the history
…or lava rendering, correctly register custom forges with the Fluid API (fixes Noaaan/MythicMetals#86)
  • Loading branch information
gliscowo committed Jul 5, 2022
1 parent c022594 commit 4f22324
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.7
# Mod Properties
mod_version=2.0.14
mod_version=2.0.15
maven_group=wraith
archives_base_name=wraith-alloy-forgery

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/wraith/alloyforgery/AlloyForgery.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import io.wispforest.owo.particles.systems.ParticleSystemController;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.resource.ResourceType;
Expand All @@ -29,7 +27,7 @@ public class AlloyForgery implements ModInitializer {

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

public static BlockEntityType<ForgeControllerBlockEntity> FORGE_CONTROLLER_BLOCK_ENTITY;
public static BlockEntityType<ForgeControllerBlockEntity> FORGE_CONTROLLER_BLOCK_ENTITY = ForgeControllerBlockEntity.Type.INSTANCE;
public static ScreenHandlerType<AlloyForgeScreenHandler> ALLOY_FORGE_SCREEN_HANDLER_TYPE;

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

@Override
@SuppressWarnings("UnstableApiUsage")
public void onInitialize() {
ALLOY_FORGE_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(id("alloy_forge"), AlloyForgeScreenHandler::new);
ALLOY_FORGE_SCREEN_HANDLER_TYPE = Registry.register(Registry.SCREEN_HANDLER, id("alloy_forge"), new ScreenHandlerType<>(AlloyForgeScreenHandler::new));

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(FuelDataLoader.INSTANCE);

ModDataLoader.load(ForgeRegistry.Loader.INSTANCE);
FORGE_CONTROLLER_BLOCK_ENTITY = ForgeControllerBlockEntity.Type.INSTANCE;

Registry.register(Registry.BLOCK_ENTITY_TYPE, id("forge_controller"), FORGE_CONTROLLER_BLOCK_ENTITY);
FluidStorage.SIDED.registerSelf(FORGE_CONTROLLER_BLOCK_ENTITY);

Registry.register(Registry.RECIPE_TYPE, AlloyForgeRecipe.Type.ID, AlloyForgeRecipe.Type.INSTANCE);
Registry.register(Registry.RECIPE_SERIALIZER, AlloyForgeRecipe.Type.ID, AlloyForgeRecipeSerializer.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class AlloyForgeScreen extends HandledScreen<AlloyForgeScreenHandler> {

public static int blockAtlasWidth = 0, blockAtlasHeight = 0;

private static final Identifier TEXTURE = AlloyForgery.id("textures/gui/forge_controller.png");
private final SpriteIdentifier lavaSpriteId = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier("block/lava_still"));

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

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

public int rootX() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/wraith/alloyforgery/forges/ForgeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.google.gson.JsonObject;
import io.wispforest.owo.registration.ComplexRegistryAction;
import io.wispforest.owo.registration.RegistryHelper;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.minecraft.block.Block;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.registry.Registry;
import wraith.alloyforgery.AlloyForgery;

import java.util.ArrayList;

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

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

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

ForgeRegistry.registerDefinition(id, definition);
FluidStorage.SIDED.registerSelf(AlloyForgery.FORGE_CONTROLLER_BLOCK_ENTITY);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RecipeManagerMixin {
public void injectForgeRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
for (var id : ForgeRegistry.getForgeIds()) {
final var forgeDefinition = ForgeRegistry.getForgeDefinition(id).get();
map.put(id, forgeDefinition.generateRecipe(id));
map.putIfAbsent(id, forgeDefinition.generateRecipe(id));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package wraith.alloyforgery.mixin;

import net.minecraft.client.texture.SpriteAtlasTexture;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(SpriteAtlasTexture.Data.class)
public interface SpriteAtlasTextureDataAccessor {
@Accessor("width")
int af$getWidth();

@Accessor("height")
int af$getHeight();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wraith.alloyforgery.mixin;

import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import wraith.alloyforgery.client.AlloyForgeScreen;

@Mixin(SpriteAtlasTexture.class)
public class SpriteAtlasTextureMixin {

@Shadow
@Final
private Identifier id;

@Inject(method = "upload", at = @At("HEAD"))
private void captureSize(SpriteAtlasTexture.Data data, CallbackInfo ci) {
if (!this.id.equals(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE)) return;

AlloyForgeScreen.blockAtlasWidth = ((SpriteAtlasTextureDataAccessor) data).af$getWidth();
AlloyForgeScreen.blockAtlasHeight = ((SpriteAtlasTextureDataAccessor) data).af$getHeight();
}

}
4 changes: 3 additions & 1 deletion src/main/resources/alloy-forgery.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"DefaultedRegistryMixin",
"HopperBlockEntityMixin",
"HopperHelperMixin",
"RecipeManagerMixin"
"RecipeManagerMixin",
"SpriteAtlasTextureDataAccessor"
],
"client": [
"SpriteAtlasTextureMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 4f22324

Please sign in to comment.