astral ports primitive

This commit is contained in:
OneLemonyBoi
2021-05-20 18:31:39 -07:00
parent ee685fbe98
commit 0cc4a287e7
14 changed files with 426 additions and 57 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -136,14 +136,21 @@ shadowJar {
repositories {
maven { url 'https://modmaven.dev/' }
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
name = "Cursemaven"
url = "https://www.cursemaven.com/"
}
maven {
url 'https://repo.spongepowered.org/maven/'
}
maven {
name 'HellFirePvP'
url 'https://maven.hellfiredev.net/'
}
maven {
name 'Curios'
url "https://maven.theillusivec4.top/"
}
}
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
@@ -164,11 +171,14 @@ dependencies {
// at runtime, use the full JEI jar
runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")
implementation fg.deobf('me.desht.pneumaticcraft:pneumaticcraft-repressurized:1.16.5-2.12.2-186');
implementation fg.deobf("curse.maven:create-328085:3278516")
implementation fg.deobf("curse.maven:astral-sorcery-241721:3156477")
implementation fg.deobf("curse.maven:curios-309927:3275653")
implementation fg.deobf("curse.maven:observerlib-316833:3162044")
// runtime deps
runtimeOnly fg.deobf("curse.maven:curios-309927:3231111")
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"

1
settings.gradle Normal file
View File

@@ -0,0 +1 @@
rootProject.name = 'masterfulmachinery'

View File

@@ -2,6 +2,10 @@ package com.ticticboooom.mods.mm.block;
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import com.ticticboooom.mods.mm.ports.storage.StarlightPortStorage;
import hellfirepvp.astralsorcery.common.block.base.BlockStarlightRecipient;
import hellfirepvp.astralsorcery.common.constellation.IWeakConstellation;
import lombok.Getter;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
@@ -26,8 +30,9 @@ import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nullable;
import java.util.Random;
public class MachinePortBlock extends Block {
public class MachinePortBlock extends Block implements BlockStarlightRecipient {
private RegistryObject<TileEntityType<?>> type;
@Getter
private String langName;
@@ -58,6 +63,7 @@ public class MachinePortBlock extends Block {
return type.get().create();
}
@Override
public ActionResultType onBlockActivated(BlockState state, World level, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult traceResult) {
if (!level.isRemote()) {
@@ -66,6 +72,7 @@ public class MachinePortBlock extends Block {
NetworkHooks.openGui(((ServerPlayerEntity) player), (MachinePortBlockEntity)blockEntity, pos);
}
}
return ActionResultType.SUCCESS;
}
@@ -73,6 +80,7 @@ public class MachinePortBlock extends Block {
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
TileEntity tile = worldIn.getTileEntity(pos);
super.onReplaced(state, worldIn, pos, newState, isMoving);
if (tile instanceof MachinePortBlockEntity){
LazyOptional<Object> lo = ((MachinePortBlockEntity) tile).getStorage().getLO();
if (lo == null){
@@ -83,7 +91,7 @@ public class MachinePortBlock extends Block {
InventoryHelper.dropInventoryItems(worldIn, pos, new ItemStackInventory((ItemStackHandler) o));
}
}
super.onReplaced(state, worldIn, pos, newState, isMoving);
tile.remove();
}
@@ -95,4 +103,17 @@ public class MachinePortBlock extends Block {
((MachinePortBlockEntity) tile).getStorage().neighborChanged();
}
}
@Override
public void receiveStarlight(World world, Random random, BlockPos blockPos, IWeakConstellation iWeakConstellation, double v) {
TileEntity tile = world.getTileEntity(blockPos);
if (tile instanceof MachinePortBlockEntity){
PortStorage storage = ((MachinePortBlockEntity) tile).getStorage();
if (storage instanceof StarlightPortStorage) {
StarlightPortStorage starlightStorage = (StarlightPortStorage) storage;
int rec = new Double(v).intValue();
starlightStorage.getInv().receiveStarlight(rec, false);
}
}
}
}

View File

@@ -32,9 +32,9 @@ public class MMLangProvider extends LanguageProvider {
}
}
this.add(MMSetup.BLUEPRINT.get(), "Blueprint");
this.add(MMSetup.STRUCTURE_DEVICE.get(), "Structure Scanner");
this.add(MMSetup.PROJECTOR_BLOCK.get(), "Structure Projector");
this.add(MMSetup.STRUCTURE_BLOCK.get(), "Structure Scanner");
// this.add(MMSetup.BLUEPRINT.get(), "Blueprint");
// this.add(MMSetup.STRUCTURE_DEVICE.get(), "Structure Scanner");
// this.add(MMSetup.PROJECTOR_BLOCK.get(), "Structure Projector");
// this.add(MMSetup.STRUCTURE_BLOCK.get(), "Structure Scanner");
}
}

View File

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

View File

@@ -0,0 +1,74 @@
package com.ticticboooom.mods.mm.inventory.as;
public class PortStarlightInventory implements IStarlightStorage {
private int stored;
private int capacity;
public PortStarlightInventory(int stored, int capacity) {
this.stored = stored;
this.capacity = capacity;
}
@Override
public int receiveStarlight(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 extractStarlight(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 getStarlightStored() {
return stored;
}
@Override
public int getMaxStarlightStored() {
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

@@ -0,0 +1,64 @@
package com.ticticboooom.mods.mm.ports.parser;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.ports.state.PortState;
import com.ticticboooom.mods.mm.ports.state.StarlightPortState;
import com.ticticboooom.mods.mm.ports.state.StarlightPortState;
import com.ticticboooom.mods.mm.ports.storage.EnergyPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import com.ticticboooom.mods.mm.ports.storage.StarlightPortStorage;
import com.ticticboooom.mods.mm.ports.storage.StarlightPortStorage;
import lombok.SneakyThrows;
import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.function.Supplier;
public class StarlightPortParser implements IPortFactory {
@Override
public Supplier<PortStorage> createStorage(JsonObject obj) {
return () -> {
DataResult<Pair<StarlightPortStorage, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(StarlightPortStorage.CODEC).apply(obj);
return apply.result().get().getFirst();
};
}
@SneakyThrows
@Override
public void write(PacketBuffer buf, PortState state) {
buf.func_240629_a_(StarlightPortState.CODEC, ((StarlightPortState) state));
}
@Override
public void setIngredients(IIngredients ingredients, List<?> stacks, boolean input) {
}
@Override
public ResourceLocation getInputOverlay() {
return new ResourceLocation(MM.ID, "block/compat_ports/starlight_cutout");
}
@Override
public ResourceLocation getOutputOverlay() {
return new ResourceLocation(MM.ID, "block/compat_ports/starlight_cutout");
}
@Override
public PortState createState(JsonObject obj) {
DataResult<Pair<StarlightPortState, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(StarlightPortState.CODEC).apply(obj);
return apply.result().get().getFirst();
}
@Override
@SneakyThrows
public PortState createState(PacketBuffer buf) {
return buf.func_240628_a_(StarlightPortState.CODEC);
}
}

View File

@@ -24,8 +24,7 @@ import java.text.NumberFormat;
import java.util.List;
public class EnergyPortState extends PortState {
public static final Codec<EnergyPortState> CODEC =RecordCodecBuilder.create(x -> x.group(
public static final Codec<EnergyPortState> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.INT.fieldOf("amount").forGetter(z -> z.amount)
).apply(x, EnergyPortState::new));

View File

@@ -0,0 +1,125 @@
package com.ticticboooom.mods.mm.ports.state;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.serialization.Codec;
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.ports.storage.StarlightPortStorage;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import com.ticticboooom.mods.mm.ports.storage.StarlightPortStorage;
import hellfirepvp.astralsorcery.common.block.base.BlockStarlightRecipient;
import hellfirepvp.astralsorcery.common.constellation.IWeakConstellation;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.IIngredientType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class StarlightPortState extends PortState {
public static final Codec<StarlightPortState> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.INT.fieldOf("amount").forGetter(z -> z.amount)
).apply(x, StarlightPortState::new));
private int amount;
public StarlightPortState(int starlight) {
this.amount = starlight;
}
@Override
public void processRequirement(List<PortStorage> storage) {
int current = amount;
for (PortStorage inv : storage) {
if (inv instanceof StarlightPortStorage) {
StarlightPortStorage StarlightInv = (StarlightPortStorage) inv;
current -= StarlightInv.getInv().extractStarlight(current, false);
if (current <= 0) {
return;
}
}
}
}
@Override
public boolean validateRequirement(List<PortStorage> storage) {
int current = amount;
for (PortStorage inv : storage) {
if (inv instanceof StarlightPortStorage) {
StarlightPortStorage StarlightInv = (StarlightPortStorage) inv;
current -= StarlightInv.getInv().extractStarlight(current, true);
if (current <= 0) {
return true;
}
}
}
return false;
}
@Override
public void processResult(List<PortStorage> storage) {
/*
int current = amount;
for (PortStorage inv : storage) {
if (inv instanceof StarlightPortStorage) {
StarlightPortStorage StarlightInv = (StarlightPortStorage) inv;
current -= StarlightInv.getInv().receiveStarlight(current, false);
if (current <= 0) {
return;
}
}
}
*/
}
@Override
public boolean validateResult(List<PortStorage> storage) {
/*
int current = amount;
for (PortStorage inv : storage) {
if (inv instanceof StarlightPortStorage) {
StarlightPortStorage StarlightInv = (StarlightPortStorage) inv;
current -= StarlightInv.getInv().receiveStarlight(current, true);
if (current <= 0) {
return true;
}
}
}
*/
return true;
// CHANGE TO FALSE
}
@Override
public ResourceLocation getName() {
return new ResourceLocation(MM.ID, "starlight");
}
@Override
public IIngredientType<?> getJeiIngredientType() {
// Am guessing is placeholder?
return MMJeiPlugin.PRESSURE_TYPE;
}
@Override
public <T> List<T> getIngredient(boolean input) {
return new ArrayList<>();
}
@Override
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
}
@Override
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {
IDrawableStatic slot = helpers.getGuiHelper().getSlotDrawable();
slot.draw(ms, x, y);
}
}

View File

@@ -1,42 +0,0 @@
package com.ticticboooom.mods.mm.ports.storage;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
public class AstralStarlightPortStorage extends PortStorage {
@Override
public <T> LazyOptional<T> getLO() {
return null;
}
@Override
public <T> boolean validate(Capability<T> cap) {
return false;
}
@Override
public CompoundNBT save(CompoundNBT nbt) {
return null;
}
@Override
public void load(CompoundNBT nbt) {
}
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
}
@Override
public void tick(MachinePortBlockEntity tile) {
}
}

View File

@@ -0,0 +1,69 @@
package com.ticticboooom.mods.mm.ports.storage;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
import com.ticticboooom.mods.mm.inventory.as.PortStarlightInventory;
import hellfirepvp.astralsorcery.common.block.base.BlockStarlightRecipient;
import hellfirepvp.astralsorcery.common.constellation.IWeakConstellation;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class StarlightPortStorage extends PortStorage {
public static final Codec<StarlightPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.INT.fieldOf("capacity").forGetter(z -> z.getInv().getMaxStarlightStored())
).apply(x, StarlightPortStorage::new));
@Getter
private PortStarlightInventory inv;
public StarlightPortStorage(int capacity) {
this.inv = new PortStarlightInventory(0, capacity);
}
@Override
public <T> LazyOptional<T> getLO() {
return null;
}
@Override
public <T> boolean validate(Capability<T> cap) {
return false;
}
@Override
public CompoundNBT save(CompoundNBT nbt) {
nbt.putInt("starlight", inv.getStarlightStored());
return nbt;
}
@Override
public void load(CompoundNBT nbt) {
inv.setStored(nbt.getInt("starlight"));
}
@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"));
screen.blit(stack, left, top, 0, 0, 175, 256);
AbstractGui.drawCenteredString(stack, Minecraft.getInstance().fontRenderer, inv.getStarlightStored() + " Starlight", left + 60, top + 30, 0xfefefe);
}
}

View File

@@ -19,5 +19,6 @@ public class MMPorts {
PORTS.put(new ResourceLocation(MM.ID, "mekanism_slurry"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_slurry"), new MekSlurryPortParser()));
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()));
}
}