manaaaaaaaaaaaaaaaaa

This commit is contained in:
OneLemonyBoi
2021-05-23 13:59:08 -07:00
parent d52ddfcb8b
commit b1092788c4
13 changed files with 231 additions and 28 deletions

View File

@@ -182,6 +182,8 @@ dependencies {
compileOnly fg.deobf("vazkii.botania:Botania:1.16.5-416:api")
runtimeOnly fg.deobf("vazkii.botania:Botania:1.16.5-416")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-51")
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"

View File

@@ -1,6 +1,7 @@
package com.ticticboooom.mods.mm.block.tile;
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
import com.ticticboooom.mods.mm.ports.storage.ManaPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import lombok.Getter;
import net.minecraft.block.BlockState;
@@ -17,11 +18,12 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import vazkii.botania.api.mana.IManaReceiver;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class MachinePortBlockEntity extends UpdatableTile implements ITickableTileEntity, INamedContainerProvider {
public class MachinePortBlockEntity extends UpdatableTile implements ITickableTileEntity, INamedContainerProvider, IManaReceiver {
private ContainerType<?> container;
@Getter
@@ -78,4 +80,34 @@ public class MachinePortBlockEntity extends UpdatableTile implements ITickableTi
update();
}
@Override
public boolean isFull() {
if (storage instanceof ManaPortStorage) {
ManaPortStorage s = (ManaPortStorage) storage;
return s.getInv().getManaStored() == s.getInv().getMaxManaStored();
}
return true;
}
@Override
public void receiveMana(int mana) {
if (storage instanceof ManaPortStorage) {
ManaPortStorage s = (ManaPortStorage) storage;
s.getInv().receiveMana(mana, false);
}
}
@Override
public boolean canReceiveManaFromBursts() {
return true;
}
@Override
public int getCurrentMana() {
if (storage instanceof ManaPortStorage) {
ManaPortStorage s = (ManaPortStorage) storage;
return s.getInv().getManaStored();
}
return 0;
}
}

View File

@@ -32,6 +32,10 @@ public class MMJeiPlugin implements IModPlugin {
public static final PNCPressureIngredientRenderer PRESSURE_TYPE_RENDERER = new PNCPressureIngredientRenderer();
public static final PNCPressureIngredientHelper PRESSURE_TYPE_HELPER = new PNCPressureIngredientHelper();
public static final ManaIngredientType MANA_TYPE = new ManaIngredientType();
public static final ManaIngredientRenderer MANA_TYPE_RENDERER = new ManaIngredientRenderer();
public static final ManaIngredientHelper MANA_TYPE_HELPER = new ManaIngredientHelper();
@Override
public ResourceLocation getPluginUid() {
return new ResourceLocation(MM.ID, "jei_main");
@@ -41,6 +45,7 @@ public class MMJeiPlugin implements IModPlugin {
public void registerIngredients(IModIngredientRegistration registration) {
registration.register(MMJeiPlugin.ENERGY_TYPE, ImmutableList.of(), ENERGY_TYPE_HELPER, ENERGY_TYPE_RENDERER);
registration.register(MMJeiPlugin.PRESSURE_TYPE, ImmutableList.of(), PRESSURE_TYPE_HELPER, PRESSURE_TYPE_RENDERER);
registration.register(MMJeiPlugin.MANA_TYPE, ImmutableList.of(), MANA_TYPE_HELPER, MANA_TYPE_RENDERER);
}
@Override

View File

@@ -1,45 +1,46 @@
package com.ticticboooom.mods.mm.client.jei.ingredients;
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
import com.ticticboooom.mods.mm.inventory.botania.PortManaInventory;
import mezz.jei.api.ingredients.IIngredientHelper;
import javax.annotation.Nullable;
public class ManaIngredientHelper implements IIngredientHelper<PressureStack> {
public class ManaIngredientHelper implements IIngredientHelper<PortManaInventory> {
@Nullable
@Override
public PressureStack getMatch(Iterable<PressureStack> ingredients, PressureStack ingredientToMatch) {
public PortManaInventory getMatch(Iterable<PortManaInventory> ingredients, PortManaInventory ingredientToMatch) {
return ingredientToMatch;
}
@Override
public String getDisplayName(PressureStack ingredient) {
public String getDisplayName(PortManaInventory ingredient) {
return "Pressure";
}
@Override
public String getUniqueId(PressureStack ingredient) {
return ingredient.getAmount() + "";
public String getUniqueId(PortManaInventory ingredient) {
return ingredient.getManaStored() + "";
}
@Override
public String getModId(PressureStack ingredient) {
return "pneumaticcraft";
public String getModId(PortManaInventory ingredient) {
return "botania";
}
@Override
public String getResourceId(PressureStack ingredient) {
return "pressure";
public String getResourceId(PortManaInventory ingredient) {
return "mana";
}
@Override
public PressureStack copyIngredient(PressureStack ingredient) {
return new PressureStack(ingredient.getAmount());
public PortManaInventory copyIngredient(PortManaInventory ingredient) {
return new PortManaInventory(0, ingredient.getManaStored());
}
@Override
public String getErrorInfo(@Nullable PressureStack ingredient) {
public String getErrorInfo(@Nullable PortManaInventory ingredient) {
return "Error";
}
}

View File

@@ -0,0 +1,28 @@
package com.ticticboooom.mods.mm.client.jei.ingredients;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.ticticboooom.mods.mm.client.jei.ingredients.model.PressureStack;
import com.ticticboooom.mods.mm.inventory.botania.PortManaInventory;
import mezz.jei.api.ingredients.IIngredientRenderer;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import javax.annotation.Nullable;
import java.util.List;
public class ManaIngredientRenderer implements IIngredientRenderer<PortManaInventory> {
@Override
public void render(MatrixStack matrixStack, int xPosition, int yPosition, @Nullable PortManaInventory ingredient) {
}
@Override
public List<ITextComponent> getTooltip(PortManaInventory ingredient, ITooltipFlag tooltipFlag) {
return Lists.newArrayList(
new StringTextComponent("Botania Mana"),
new StringTextComponent(ingredient.getManaStored() + "Units")
);
}
}

View File

@@ -0,0 +1,11 @@
package com.ticticboooom.mods.mm.client.jei.ingredients;
import com.ticticboooom.mods.mm.inventory.botania.PortManaInventory;
import mezz.jei.api.ingredients.IIngredientType;
public class ManaIngredientType implements IIngredientType<PortManaInventory> {
@Override
public Class<? extends PortManaInventory> getIngredientClass() {
return PortManaInventory.class;
}
}

View File

@@ -0,0 +1,47 @@
package com.ticticboooom.mods.mm.inventory.botania;
public interface IManaStorage {
/**
* Adds Mana to the storage. Returns quantity of Mana that was accepted.
*
* @param maxReceive
* Maximum amount of Mana to be inserted.
* @param simulate
* If TRUE, the insertion will only be simulated.
* @return Amount of Mana that was (or would have been, if simulated) accepted by the storage.
*/
int receiveMana(int maxReceive, boolean simulate);
/**
* Removes Mana from the storage. Returns quantity of Mana that was removed.
*
* @param maxExtract
* Maximum amount of Mana to be extracted.
* @param simulate
* If TRUE, the extraction will only be simulated.
* @return Amount of Mana that was (or would have been, if simulated) extracted from the storage.
*/
int extractMana(int maxExtract, boolean simulate);
/**
* Returns the amount of Mana currently stored.
*/
int getManaStored();
/**
* Returns the maximum amount of Mana that can be stored.
*/
int getMaxManaStored();
/**
* Returns if this storage can have Mana extracted.
* If this is false, then any calls to extractMana will return 0.
*/
boolean canExtract();
/**
* Used to determine if this storage can receive Mana.
* If this is false, then any calls to receiveMana will return 0.
*/
boolean canReceive();
}

View File

@@ -0,0 +1,74 @@
package com.ticticboooom.mods.mm.inventory.botania;
public class PortManaInventory implements IManaStorage {
private int stored;
private int capacity;
public PortManaInventory(int stored, int capacity) {
this.stored = stored;
this.capacity = capacity;
}
@Override
public int receiveMana(int maxReceive, boolean simulate) {
if (simulate) {
if ((long)maxReceive + stored > capacity) {
return maxReceive - (stored + maxReceive - capacity);
} else {
return maxReceive;
}
}
if ((long)maxReceive + stored > capacity) {
int result = maxReceive - (stored + maxReceive - capacity);
stored = capacity;
return result;
} else {
stored += maxReceive;
return maxReceive;
}
}
@Override
public int extractMana(int maxExtract, boolean simulate) {
if (simulate) {
if (stored - maxExtract < 0) {
return stored;
} else {
return maxExtract;
}
}
if (stored - maxExtract < 0) {
int result = stored;
stored = 0;
return result;
} else {
stored -= maxExtract;
return maxExtract;
}
}
@Override
public int getManaStored() {
return stored;
}
@Override
public int getMaxManaStored() {
return capacity;
}
@Override
public boolean canExtract() {
return stored > 0;
}
@Override
public boolean canReceive() {
return stored < capacity;
}
public void setStored(int amount) {
this.stored = amount;
}
}

View File

@@ -6,6 +6,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.client.jei.category.MMJeiPlugin;
import com.ticticboooom.mods.mm.client.jei.ingredients.model.EnergyStack;
import com.ticticboooom.mods.mm.inventory.botania.PortManaInventory;
import com.ticticboooom.mods.mm.ports.storage.EnergyPortStorage;
import com.ticticboooom.mods.mm.ports.storage.ManaPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
@@ -17,6 +18,7 @@ import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.IIngredientType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import vazkii.botania.api.mana.IManaReceiver;
import java.util.List;
@@ -57,7 +59,7 @@ public static final Codec<ManaPortState> CODEC = RecordCodecBuilder.create(x ->
@Override
public ResourceLocation getName() {
return new ResourceLocation(MM.ID, "mana");
return new ResourceLocation(MM.ID, "botania_mana");
}
@Override
@@ -68,9 +70,9 @@ public static final Codec<ManaPortState> CODEC = RecordCodecBuilder.create(x ->
@Override
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
IGuiIngredientGroup<EnergyStack> group = layout.getIngredientsGroup(MMJeiPlugin.ENERGY_TYPE);
IGuiIngredientGroup<PortManaInventory> group = layout.getIngredientsGroup(MMJeiPlugin.MANA_TYPE);
group.init(typeIndex, input, x + 1, y + 1);
group.set(typeIndex, new EnergyStack(amount));
group.set(typeIndex, new PortManaInventory(0, amount));
if (this.getChance() < 1){
group.addTooltipCallback((s, a, b, c) -> {
if (s == typeIndex) {
@@ -82,6 +84,6 @@ public static final Codec<ManaPortState> CODEC = RecordCodecBuilder.create(x ->
@Override
public IIngredientType<?> getJeiIngredientType() {
return MMJeiPlugin.ENERGY_TYPE;
return MMJeiPlugin.MANA_TYPE;
}
}

View File

@@ -5,6 +5,7 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.inventory.PortEnergyInventory;
import com.ticticboooom.mods.mm.inventory.botania.PortManaInventory;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
@@ -17,15 +18,15 @@ import net.minecraftforge.energy.CapabilityEnergy;
public class ManaPortStorage extends PortStorage {
public static final Codec<ManaPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.INT.fieldOf("capacity").forGetter(z -> z.inv.getMaxEnergyStored())
Codec.INT.fieldOf("capacity").forGetter(z -> z.inv.getMaxManaStored())
).apply(x, ManaPortStorage::new));
@Getter
private final PortEnergyInventory inv;
private final LazyOptional<PortEnergyInventory> invLO;
private final PortManaInventory inv;
private final LazyOptional<PortManaInventory> invLO;
public ManaPortStorage(int capacity) {
this.inv = new PortEnergyInventory(0, capacity);
this.inv = new PortManaInventory(0, capacity);
invLO = LazyOptional.of(() -> this.inv);
}
@@ -36,12 +37,12 @@ public class ManaPortStorage extends PortStorage {
@Override
public <T> boolean validate(Capability<T> cap) {
return cap == CapabilityEnergy.ENERGY;
return false;
}
@Override
public CompoundNBT save(CompoundNBT nbt) {
nbt.putInt("stored", inv.getEnergyStored());
nbt.putInt("stored", inv.getManaStored());
return nbt;
}
@@ -54,17 +55,16 @@ public class ManaPortStorage extends PortStorage {
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation(MM.ID, "textures/gui/port_gui.png"));
Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation(MM.ID, "textures/gui/mana_gui.png"));
screen.blit(stack, left, top, 0, 0, 175, 256);
int barOffsetX = 175 - 30;
int barOffsetY = 20;
screen.blit(stack, left + barOffsetX, top + barOffsetY, 175, 18, 18, 108);
float amount = 0;
if (inv.getMaxEnergyStored() > 0) {
amount = (float)inv.getEnergyStored() / inv.getMaxEnergyStored();
if (inv.getMaxManaStored() > 0) {
amount = (float)inv.getManaStored() / inv.getMaxManaStored();
}
screen.blit(stack, left + barOffsetX, top + barOffsetY, 193, 18, 18, (int) (108 * amount));
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer,Math.round((float)10000 * amount) / 100.f + "%", left + 30, top + 60, 0xfefefe);
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getEnergyStored() + "FE", left + 30, top + 80, 0xfefefe);
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getManaStored() + "Mana", left + 30, top + 60, 0xfefefe);
}
}

View File

@@ -20,5 +20,6 @@ public class MMPorts {
PORTS.put(new ResourceLocation(MM.ID, "pncr_pressure"),new MasterfulPortType(new ResourceLocation(MM.ID, "pncr_pressure"), new PneumaticPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "create_rotation"),new MasterfulPortType(new ResourceLocation(MM.ID, "create_rotation"), new RotationPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "starlight"),new MasterfulPortType(new ResourceLocation(MM.ID, "starlight"), new StarlightPortParser()));
PORTS.put(new ResourceLocation(MM.ID, "botania_mana"),new MasterfulPortType(new ResourceLocation(MM.ID, "botania_mana"), new ManaPortParser()));
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB