Skip to content

Commit

Permalink
support for MI 0.4 and deprecate 0.3 module
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed May 25, 2021
1 parent 4c649a0 commit cbe6123
Show file tree
Hide file tree
Showing 20 changed files with 393 additions and 4 deletions.
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ include "fast-transfer-lib"
include "industrial-revolution"
include "kibe"
include "lib-block-attributes"
include "modern-industrialization"
include "modern-industrialization-3" // TODO: Remove
include "modern-industrialization-4"
include "team-reborn-energy"
include "tech-reborn"
include "vanilla"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: Remove

repositories {
maven {
url "https://mod-buildcraft.com/maven"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import static badasintended.megane.util.MeganeUtils.intRange;

// TODO: Remove
@Deprecated
public class ModernIndustrialization implements MeganeModule {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

// TODO: Remove
@Mixin(CreativeTankBlockEntity.class)
public interface ACreativeTankBlockEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

// TODO: Remove
@Mixin(MachineBlockEntity.class)
public interface AMachineBlockEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

// TODO: Remove
@Mixin(MultiblockMachineBlockEntity.class)
public interface AMultiblockMachineBlockEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

// TODO: Remove
@Mixin(TankBlockEntity.class)
public interface ATankBlockEntity {

Expand Down
22 changes: 22 additions & 0 deletions src/modern-industrialization-3/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"schemaVersion": 1,
"id" : "megane-modern-industrialization-3",
"version" : "${version}",
"authors" : ["deirn"],
"license" : "MIT",
"icon" : "assets/megane/icon.png",
"mixins" : ["megane-modern-industrialization-3.mixins.json"],
"depends" : {
"megane-base" : "*",
"modern_industrialization": "0.3.x"
},
"custom" : {
"megane:modules": [
"badasintended.megane.impl.ModernIndustrialization"
],
"modmenu" : {
"parent": "megane",
"badges": ["deprecated"]
}
}
}
16 changes: 16 additions & 0 deletions src/modern-industrialization-4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repositories {
maven {
url "https://raw.githubusercontent.com/Technici4n/Technici4n-maven/master/"
content {
includeGroup "net.fabricmc.fabric-api"
}
}
}

dependencies {
implFor "curse.maven:modern-industrialization-405388:3321898"

modCompileOnly "net.fabricmc.fabric-api:fabric-transfer-api-v1:0.1.0+7678d00a7d"
}

apply from: "impl.gradle"
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package badasintended.megane.impl;

import java.util.List;

import aztech.modern_industrialization.blocks.creativetank.CreativeTankBlockEntity;
import aztech.modern_industrialization.blocks.tank.TankBlockEntity;
import aztech.modern_industrialization.inventory.ConfigurableFluidStack;
import aztech.modern_industrialization.inventory.ConfigurableItemStack;
import aztech.modern_industrialization.machines.MachineBlockEntity;
import aztech.modern_industrialization.machines.components.CrafterComponent;
import aztech.modern_industrialization.machines.components.EnergyComponent;
import aztech.modern_industrialization.machines.components.MachineInventoryComponent;
import badasintended.megane.api.MeganeModule;
import badasintended.megane.api.provider.EnergyProvider;
import badasintended.megane.api.provider.FluidInfoProvider;
import badasintended.megane.api.provider.FluidProvider;
import badasintended.megane.api.provider.InventoryProvider;
import badasintended.megane.api.provider.ProgressProvider;
import badasintended.megane.api.registry.MeganeClientRegistrar;
import badasintended.megane.api.registry.MeganeRegistrar;
import badasintended.megane.impl.mixin.modern_industrialization.ACraftingFluid;
import badasintended.megane.impl.mixin.modern_industrialization.ATankBlockEntity;
import badasintended.megane.impl.mixin.modern_industrialization.CrafterComponentHolder;
import badasintended.megane.impl.mixin.modern_industrialization.EnergyComponentHolder;
import badasintended.megane.impl.mixin.modern_industrialization.EnergyInputsComponentHolder;
import badasintended.megane.impl.mixin.modern_industrialization.EnergyOutputsComponentHolder;
import badasintended.megane.impl.mixin.modern_industrialization.MultiblockInventoryComponentHolder;
import badasintended.megane.util.MeganeUtils;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ModernIndustrialization implements MeganeModule {

@Override
public void register(MeganeRegistrar registrar) {
registrar
.energy(EnergyComponentHolder.class, EnergyProvider.of(
t -> t.getEnergy().getEu(),
t -> t.getEnergy().getCapacity()
))
.energy(EnergyInputsComponentHolder.class, EnergyProvider.of(
t -> !t.getEnergyInputs().isEmpty(),
t -> t.getEnergyInputs().stream().mapToDouble(EnergyComponent::getEu).sum(),
t -> t.getEnergyInputs().stream().mapToDouble(EnergyComponent::getCapacity).sum()
))
.energy(EnergyOutputsComponentHolder.class, EnergyProvider.of(
t -> !t.getEnergyOutputs().isEmpty(),
t -> t.getEnergyOutputs().stream().mapToDouble(EnergyComponent::getEu).sum(),
t -> t.getEnergyOutputs().stream().mapToDouble(EnergyComponent::getCapacity).sum()
))
.fluid(TankBlockEntity.class, FluidProvider.of(
t -> 1,
(t, i) -> t.resource(),
(t, i) -> t.amount() / 81.0,
(t, i) -> ((ATankBlockEntity) t).getCapacity() / 81.0
))
.fluid(CreativeTankBlockEntity.class, FluidProvider.of(
t -> 1,
(t, i) -> t.resource(),
(t, i) -> -1,
(t, i) -> -1
))
.fluid(MachineBlockEntity.class, FluidProvider.of(
t -> t.getInventory().getFluidStacks().size(),
(t, i) -> t.getInventory().getFluidStacks().get(i).resource(),
(t, i) -> t.getInventory().getFluidStacks().get(i).getAmount() / 81.0,
(t, i) -> t.getInventory().getFluidStacks().get(i).getCapacity() / 81.0
))
.fluid(999, MultiblockInventoryComponentHolder.class, new FluidProvider<MultiblockInventoryComponentHolder>() {
List<ConfigurableFluidStack> input;
List<ConfigurableFluidStack> output;

@Override
public int getSlotCount(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder) {
input = multiblockInventoryComponentHolder.getInventory().getFluidInputs();
output = multiblockInventoryComponentHolder.getInventory().getFluidOutputs();
return input.size() + output.size();
}

ConfigurableFluidStack getFluidStack(int slot) {
return slot < input.size()
? input.get(slot)
: output.get(slot - input.size());
}

@Override
public @Nullable Fluid getFluid(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder, int slot) {
return getFluidStack(slot).getFluid();
}

@Override
public double getStored(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder, int slot) {
return getFluidStack(slot).getAmount() / 81.0;
}

@Override
public double getMax(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder, int slot) {
return getFluidStack(slot).getCapacity() / 81.0;
}
})
.inventory(MachineBlockEntity.class, InventoryProvider.of(
t -> t.getInventory().getItemStacks().size(),
(t, i) -> {
ConfigurableItemStack stack = t.getInventory().getItemStacks().get(i);
return stack.resource().toStack(stack.getCount());
}
))
.inventory(999, MultiblockInventoryComponentHolder.class, new InventoryProvider<MultiblockInventoryComponentHolder>() {
List<ConfigurableItemStack> input;
List<ConfigurableItemStack> output;

@Override
public int size(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder) {
input = multiblockInventoryComponentHolder.getInventory().getItemInputs();
output = multiblockInventoryComponentHolder.getInventory().getItemOutputs();
return input.size() + output.size();
}

@Override
public @NotNull ItemStack getStack(MultiblockInventoryComponentHolder multiblockInventoryComponentHolder, int slot) {
ConfigurableItemStack stack = slot < input.size()
? input.get(slot)
: output.get(slot - input.size());
return stack.resource().toStack(stack.getCount());
}
})
.progress(CrafterComponentHolder.class, new ProgressProvider<CrafterComponentHolder>() {
CrafterComponent crafter;
CrafterComponent.Inventory inventory;

int inputCount;

boolean isNotMultiBlock = false;
MachineInventoryComponent machineInventoryComponent;

@Override
public int[] getInputSlots(CrafterComponentHolder crafterComponentHolder) {
crafter = crafterComponentHolder.getCrafter();
inventory = ((CrafterComponentHolder.Inventory) crafter).getInventory();

isNotMultiBlock = inventory instanceof MachineInventoryComponent;

if (isNotMultiBlock) {
machineInventoryComponent = (MachineInventoryComponent) inventory;
inputCount = machineInventoryComponent.itemInputCount;
} else {
inputCount = inventory.getItemInputs().size();
}

return MeganeUtils.intRange(0, inputCount);
}

@Override
public int[] getOutputSlots(CrafterComponentHolder crafterComponentHolder) {
return MeganeUtils.intRange(inputCount, isNotMultiBlock
? machineInventoryComponent.itemOutputCount
: inventory.getItemOutputs().size());
}

@Override
public @NotNull ItemStack getStack(CrafterComponentHolder crafterComponentHolder, int slot) {
ConfigurableItemStack stack;
if (isNotMultiBlock) {
stack = machineInventoryComponent.inventory.getItemStacks().get(slot);
} else {
stack = slot < inputCount
? inventory.getItemInputs().get(slot)
: inventory.getItemOutputs().get(slot);
}
return stack.getItemKey().toStack(stack.getCount());
}

@Override
public int getPercentage(CrafterComponentHolder crafterComponentHolder) {
return (int) (crafter.getProgress() * 100);
}
});
}

@Override
public void registerClient(MeganeClientRegistrar registrar) {
registrar
.fluid(ACraftingFluid.class, FluidInfoProvider.of(f -> f.getBlock().getColor(), f -> f.getBlock().getName()))
.energy("modern_industrialization", 0xB70000, "EU");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package badasintended.megane.impl.mixin.modern_industrialization;

import aztech.modern_industrialization.fluid.CraftingFluid;
import aztech.modern_industrialization.fluid.CraftingFluidBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(CraftingFluid.class)
public interface ACraftingFluid {

@Accessor
CraftingFluidBlock getBlock();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package badasintended.megane.impl.mixin.modern_industrialization;

import aztech.modern_industrialization.blocks.tank.TankBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(TankBlockEntity.class)
public interface ATankBlockEntity {

@Accessor
long getCapacity();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package badasintended.megane.impl.mixin.modern_industrialization;

import aztech.modern_industrialization.machines.blockentities.AbstractCraftingMachineBlockEntity;
import aztech.modern_industrialization.machines.blockentities.multiblocks.AbstractCraftingMultiblockBlockEntity;
import aztech.modern_industrialization.machines.components.CrafterComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin({
AbstractCraftingMachineBlockEntity.class,
AbstractCraftingMultiblockBlockEntity.class
})
public interface CrafterComponentHolder {

@Accessor
CrafterComponent getCrafter();

@Mixin(CrafterComponent.class)
interface Inventory {

@Accessor
CrafterComponent.Inventory getInventory();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package badasintended.megane.impl.mixin.modern_industrialization;

import aztech.modern_industrialization.machines.blockentities.AbstractStorageMachineBlockEntity;
import aztech.modern_industrialization.machines.blockentities.ElectricCraftingMachineBlockEntity;
import aztech.modern_industrialization.machines.blockentities.ElectricWaterPumpBlockEntity;
import aztech.modern_industrialization.machines.blockentities.EnergyFromFluidMachineBlockEntity;
import aztech.modern_industrialization.machines.blockentities.hatches.EnergyHatch;
import aztech.modern_industrialization.machines.components.EnergyComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin({
AbstractStorageMachineBlockEntity.class,
ElectricCraftingMachineBlockEntity.class,
ElectricWaterPumpBlockEntity.class,
EnergyFromFluidMachineBlockEntity.class,
EnergyHatch.class
})
public interface EnergyComponentHolder {

@Accessor
EnergyComponent getEnergy();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package badasintended.megane.impl.mixin.modern_industrialization;

import java.util.List;

import aztech.modern_industrialization.machines.blockentities.multiblocks.ElectricBlastFurnaceBlockEntity;
import aztech.modern_industrialization.machines.blockentities.multiblocks.ElectricCraftingMultiblockBlockEntity;
import aztech.modern_industrialization.machines.components.EnergyComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin({
ElectricBlastFurnaceBlockEntity.class,
ElectricCraftingMultiblockBlockEntity.class
})
public interface EnergyInputsComponentHolder {

@Accessor
List<EnergyComponent> getEnergyInputs();

}
Loading

0 comments on commit cbe6123

Please sign in to comment.