mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-01-19 00:47:25 +01:00
adding machine ProcessIngredientType
This commit is contained in:
@@ -3,6 +3,7 @@ package com.ticticboooom.mods.mm;
|
||||
import com.ticticboooom.mods.mm.block.ter.model.controller.ControllerBlockModel;
|
||||
import com.ticticboooom.mods.mm.block.ter.model.port.PortBlockModel;
|
||||
import com.ticticboooom.mods.mm.client.screen.ControllerScreen;
|
||||
import com.ticticboooom.mods.mm.client.screen.PortScreen;
|
||||
import com.ticticboooom.mods.mm.net.MMNetworkManager;
|
||||
import com.ticticboooom.mods.mm.ports.PortTypeRegistry;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortType;
|
||||
@@ -86,6 +87,7 @@ public class ModRoot {
|
||||
RenderTypeLookup.setRenderLayer(MMBlocks.CONTROLLER.get(), RenderType.getTranslucent());
|
||||
RenderTypeLookup.setRenderLayer(MMBlocks.PORT.get(), RenderType.getTranslucent());
|
||||
ScreenManager.registerFactory(MMContainerTypes.CONTROLLER.get(), ControllerScreen::new);
|
||||
ScreenManager.registerFactory(MMContainerTypes.PORT.get(), PortScreen::new);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,26 @@ public class Ref {
|
||||
public static final ResourceLocation PORT_GROUP = res("port_group");
|
||||
public static final ResourceLocation MODIFIABLE = res("modifiable");
|
||||
}
|
||||
public static final ResourceLocation PROCESS_INGREDIENT_TYPE = res("processes/ingredient_type");
|
||||
public static final class PIT {
|
||||
public static final ResourceLocation ITEMS = res("items");
|
||||
}
|
||||
|
||||
public static final ResourceLocation PROCESS_OUTPUT_TYPE = res("processes/output_type");
|
||||
public static final class POT {
|
||||
public static final ResourceLocation ITEMS = res("items");
|
||||
}
|
||||
|
||||
public static final ResourceLocation PREPROCESSOR_TYPE = res("processes/preprocessor_type");
|
||||
public static final class PT {
|
||||
public static final ResourceLocation MODIFIABLE = res("modifiable");
|
||||
}
|
||||
|
||||
public static final ResourceLocation MODIFIER_ACTIONS = res("processes/modifier_actions");
|
||||
public static final class MA {
|
||||
public static final ResourceLocation NOTHING = res("nothing");
|
||||
public static final ResourceLocation SPEED = res("speed");
|
||||
}
|
||||
}
|
||||
|
||||
public static final ResourceLocation JEI_PLUGIN = res("jei");
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
package com.ticticboooom.mods.mm.block;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.tile.ControllerTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.setup.MMTiles;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.sound.sampled.Port;
|
||||
import java.util.List;
|
||||
|
||||
public class PortBlock extends Block {
|
||||
@@ -32,5 +43,15 @@ public class PortBlock extends Block {
|
||||
return MMTiles.PORT.get().create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!worldIn.isRemote()) {
|
||||
TileEntity blockEntity = worldIn.getTileEntity(pos);
|
||||
if (blockEntity instanceof PortTile) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, (PortTile)blockEntity, pos);
|
||||
}
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.data.DataRegistry;
|
||||
import com.ticticboooom.mods.mm.data.model.ControllerModel;
|
||||
import com.ticticboooom.mods.mm.data.model.PortModel;
|
||||
import com.ticticboooom.mods.mm.ports.PortTypeRegistry;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortType;
|
||||
import com.ticticboooom.mods.mm.setup.MMBlocks;
|
||||
import com.ticticboooom.mods.mm.setup.MMRegistries;
|
||||
import com.ticticboooom.mods.mm.util.TagHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -26,11 +29,13 @@ public class PortBlockItem extends BlockItem {
|
||||
|
||||
@Override
|
||||
protected boolean onBlockPlaced(BlockPos pos, World worldIn, @Nullable PlayerEntity player, ItemStack stack, BlockState state) {
|
||||
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (tileEntity instanceof PortTile) {
|
||||
PortTile controller = (PortTile) tileEntity;
|
||||
controller.portModel = getModel(stack);
|
||||
PortTile tile = (PortTile) tileEntity;
|
||||
PortModel model = getModel(stack);
|
||||
PortType type = PortTypeRegistry.PORT_TYPES.get(model.type);
|
||||
tile.storage = type.parseStorage(model.json);
|
||||
tile.portModel = model;
|
||||
}
|
||||
return super.onBlockPlaced(pos, worldIn, player, stack, state);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.ter.model.controller.ControllerBlockModel;
|
||||
import com.ticticboooom.mods.mm.client.container.ControllerContainer;
|
||||
import com.ticticboooom.mods.mm.data.DataRegistry;
|
||||
import com.ticticboooom.mods.mm.data.ProcessModel;
|
||||
import com.ticticboooom.mods.mm.data.model.ControllerModel;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.net.MMNetworkManager;
|
||||
import com.ticticboooom.mods.mm.net.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.setup.MMBlocks;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.process.PreProcessorType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessIngredientType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessOutputType;
|
||||
import com.ticticboooom.mods.mm.setup.MMRegistries;
|
||||
import com.ticticboooom.mods.mm.setup.MMTiles;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
import com.ticticboooom.mods.mm.structures.keys.*;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Rotations;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
@@ -38,9 +39,9 @@ import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ControllerTile extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
|
||||
public ControllerTile() {
|
||||
@@ -49,6 +50,10 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
|
||||
public ControllerModel controllerModel;
|
||||
public String status = "";
|
||||
public List<PortTile> activePorts = new ArrayList<>();
|
||||
public Map<String, List<String>> activeModifiers = new HashMap<>();
|
||||
private MachineProcessContext ctx;
|
||||
private MachineStructureContext sctx;
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
@@ -57,13 +62,102 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
MMNetworkManager.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(this.pos, compound));
|
||||
}
|
||||
if (controllerModel == null || controllerModel.id == null) {
|
||||
activePorts.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (sctx == null) {
|
||||
sctx = new MachineStructureContext();
|
||||
}
|
||||
activeModifiers.clear();
|
||||
StructureModel valid = getValid();
|
||||
if (valid == null) {
|
||||
activePorts.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx != null && ctx.processModel != null) {
|
||||
if (!validProcess(ctx.processModel, ctx)) {
|
||||
ctx = null;
|
||||
}
|
||||
}
|
||||
if (ctx == null || ctx.processModel == null) {
|
||||
ctx = new MachineProcessContext();
|
||||
List<PortStorage> inputs = new ArrayList<>();
|
||||
List<PortStorage> outputs = new ArrayList<>();
|
||||
for (PortTile activePort : activePorts) {
|
||||
if (activePort.portModel.input) {
|
||||
inputs.add(activePort.storage);
|
||||
} else {
|
||||
outputs.add(activePort.storage);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.inputs = inputs;
|
||||
ctx.outputs = outputs;
|
||||
ctx.structureId = valid.id;
|
||||
ctx.structureCtx = sctx;
|
||||
|
||||
boolean found = false;
|
||||
for (Map.Entry<ResourceLocation, ProcessModel> entry : DataRegistry.PROCESSES.entrySet()) {
|
||||
ProcessModel value = entry.getValue();
|
||||
if (!validProcess(value, ctx)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx.processModel = value;
|
||||
ctx.ticks = value.ticks;
|
||||
ctx.processId = entry.getKey();
|
||||
for (Map.Entry<String, PreProcessorType.Value> pp : value.preprocessors.entrySet()) {
|
||||
ResourceLocation type = pp.getValue().type;
|
||||
PreProcessorType ppType = MMRegistries.PREPROCESSOR_TYPES.getValue(type);
|
||||
ppType.process(pp.getValue(), ctx);
|
||||
}
|
||||
ctx.maxTicks = ctx.ticks;
|
||||
found = true;
|
||||
}
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ctx != null && ctx.processModel != null) {
|
||||
process(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validProcess(ProcessModel value, MachineProcessContext ctx) {
|
||||
for (Map.Entry<String, ProcessIngredientType.Value> input : value.inputs.entrySet()) {
|
||||
ProcessIngredientType type = MMRegistries.PROCESS_INGREDIENT_TYPES.getValue(input.getValue().type);
|
||||
if (!type.canProcess(input.getValue(), ctx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, ProcessOutputType.Value> input : value.outputs.entrySet()) {
|
||||
ProcessOutputType type = MMRegistries.PROCESS_OUTPUT_TYPES.getValue(input.getValue().type);
|
||||
if (!type.canProcess(input.getValue(), ctx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean process(MachineProcessContext ctx) {
|
||||
ctx.ticks--;
|
||||
if (ctx.ticks > 0) {
|
||||
status = "Processing: " + (100 - MathHelper.floor((float) ctx.ticks / ctx.maxTicks * 100)) + "%";
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, ProcessIngredientType.Value> input : ctx.processModel.inputs.entrySet()) {
|
||||
ProcessIngredientType type = MMRegistries.PROCESS_INGREDIENT_TYPES.getValue(input.getValue().type);
|
||||
type.process(input.getValue(), ctx);
|
||||
}
|
||||
for (Map.Entry<String, ProcessOutputType.Value> input : ctx.processModel.outputs.entrySet()) {
|
||||
ProcessOutputType type = MMRegistries.PROCESS_OUTPUT_TYPES.getValue(input.getValue().type);
|
||||
type.process(input.getValue(), ctx);
|
||||
}
|
||||
this.ctx = null;
|
||||
this.sctx = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private StructureModel getValid() {
|
||||
@@ -91,10 +185,17 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isValidBlockSingleWithKey(StructureModel.PositionedKey positionedKey, StructureModel model) {
|
||||
BlockState blockState = world.getBlockState(this.pos.add(positionedKey.pos));
|
||||
private boolean isValidBlockSingleWithKey(StructureModel.PositionedKey positionedKey, StructureModel model, boolean recordPorts) {
|
||||
BlockPos abspos = this.pos.add(positionedKey.pos);
|
||||
BlockState blockState = world.getBlockState(abspos);
|
||||
if (recordPorts) {
|
||||
TileEntity tileEntity = world.getTileEntity(abspos);
|
||||
if (tileEntity instanceof PortTile) {
|
||||
activePorts.add(((PortTile) tileEntity));
|
||||
}
|
||||
}
|
||||
StructureKeyType value = MMRegistries.STRUCTURE_KEY_TYPES.getValue(positionedKey.type);
|
||||
return value.isValidPlacement(this.pos.add(positionedKey.pos), model, blockState, positionedKey.data, world);
|
||||
return value.isValidPlacement(this.pos.add(positionedKey.pos), model, blockState, positionedKey.data, world, sctx);
|
||||
}
|
||||
|
||||
private List<StructureModel.PositionedKey> rotateKeys(StructureModel model, Rotation rotation) {
|
||||
@@ -108,14 +209,16 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
|
||||
private boolean isValidBlockPlacement(StructureModel model) {
|
||||
Rotation rotation = Rotation.NONE;
|
||||
boolean shouldRecordPorts = activePorts.isEmpty();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
boolean found = true;
|
||||
boolean valid = true;
|
||||
for (StructureModel.PositionedKey positionedKey : rotateKeys(model, rotation)) {
|
||||
if (!isValidBlockSingleWithKey(positionedKey, model)) {
|
||||
found = false;
|
||||
if (!isValidBlockSingleWithKey(positionedKey, model, shouldRecordPorts)) {
|
||||
activePorts.clear();
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
if (valid) {
|
||||
return true;
|
||||
}
|
||||
rotation = rotation.add(Rotation.CLOCKWISE_90);
|
||||
@@ -148,6 +251,7 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
String controllerId = nbt.getString("ControllerId");
|
||||
controllerModel = DataRegistry.CONTROLLERS.get(ResourceLocation.tryCreate(controllerId));
|
||||
}
|
||||
status = nbt.getString("status");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,6 +259,7 @@ public class ControllerTile extends TileEntity implements ITickableTileEntity, I
|
||||
if (controllerModel != null) {
|
||||
compound.putString("ControllerId", controllerModel.id.toString());
|
||||
}
|
||||
compound.putString("status", status);
|
||||
return super.write(compound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,41 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.ter.model.port.PortBlockModel;
|
||||
import com.ticticboooom.mods.mm.client.container.PortContainer;
|
||||
import com.ticticboooom.mods.mm.data.DataRegistry;
|
||||
import com.ticticboooom.mods.mm.data.model.PortModel;
|
||||
import com.ticticboooom.mods.mm.net.MMNetworkManager;
|
||||
import com.ticticboooom.mods.mm.net.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.ports.PortTypeRegistry;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortType;
|
||||
import com.ticticboooom.mods.mm.setup.MMTiles;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||
import net.minecraftforge.fml.common.thread.EffectiveSide;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PortTile extends TileEntity implements ITickableTileEntity {
|
||||
public class PortTile extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
|
||||
public PortTile() {
|
||||
super(MMTiles.PORT.get());
|
||||
}
|
||||
|
||||
public PortModel portModel;
|
||||
public PortStorage storage;
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
@@ -45,6 +57,12 @@ public class PortTile extends TileEntity implements ITickableTileEntity {
|
||||
public void read(BlockState state, CompoundNBT nbt) {
|
||||
if (nbt.contains("PortId")) {
|
||||
this.portModel = DataRegistry.PORTS.get(ResourceLocation.tryCreate(nbt.getString("PortId")));
|
||||
ResourceLocation type = this.portModel.type;
|
||||
PortType portType = PortTypeRegistry.PORT_TYPES.get(type);
|
||||
this.storage = portType.parseStorage(this.portModel.json);
|
||||
if (nbt.contains("storage")) {
|
||||
storage.load(nbt.getCompound("storage"));
|
||||
}
|
||||
}
|
||||
super.read(state, nbt);
|
||||
}
|
||||
@@ -53,7 +71,21 @@ public class PortTile extends TileEntity implements ITickableTileEntity {
|
||||
public CompoundNBT write(CompoundNBT compound) {
|
||||
if (portModel != null && portModel.id != null) {
|
||||
compound.putString("PortId", portModel.id.toString());
|
||||
compound.put("storage", storage.save(compound));
|
||||
}
|
||||
return super.write(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return portModel.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
|
||||
return new PortContainer(this, p_createMenu_2_, p_createMenu_1_);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.ticticboooom.mods.mm.client.container;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.tile.ControllerTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.setup.MMContainerTypes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class PortContainer extends Container {
|
||||
private PortTile tile;
|
||||
|
||||
public PortContainer(PortTile tile, PlayerInventory inv, int id) {
|
||||
super(MMContainerTypes.PORT.get(), id);
|
||||
this.tile = tile;
|
||||
tile.storage.setupContainer(this, inv, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public PortContainer(int windowId, PlayerInventory inv, PacketBuffer data) {
|
||||
this((PortTile) inv.player.world.getTileEntity(data.readBlockPos()), inv, windowId);
|
||||
}
|
||||
|
||||
public PortTile getTile() {
|
||||
return tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot addSlot(Slot slot) {
|
||||
return super.addSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity p_82846_1_, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Object o = tile.storage.getLazyOptional(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).orElse(null);
|
||||
if (o instanceof ItemStackHandler) {
|
||||
ItemStackHandler handler = ((ItemStackHandler) o);
|
||||
Slot slot = this.getSlot(index);
|
||||
if (slot.getHasStack()) {
|
||||
ItemStack itemStack1 = slot.getStack();
|
||||
itemStack = itemStack1.copy();
|
||||
if (index < handler.getSlots()) {
|
||||
if (!this.mergeItemStack(itemStack1, handler.getSlots(), this.inventorySlots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemStack1, 0, handler.getSlots(), false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack1.isEmpty()) {
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ticticboooom.mods.mm.client.screen;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.client.container.ControllerContainer;
|
||||
import com.ticticboooom.mods.mm.client.container.PortContainer;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class PortScreen extends ContainerScreen<PortContainer> {
|
||||
public PortScreen(PortContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, float p_230430_4_) {
|
||||
super.render(stack, mouseX, mouseY, p_230430_4_);
|
||||
|
||||
this.renderHoveredTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack stack, int x0, int y0) {
|
||||
drawString(stack, this.minecraft.fontRenderer, container.getTile().portModel.name, 7, -15, 0xfefefe);
|
||||
drawString(stack, this.minecraft.fontRenderer, "Inventory", 7, 110, 0xfefefe);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack stack, float partialTicks, int x, int y) {
|
||||
this.renderBackground(stack);
|
||||
container.getTile().storage.render(stack, x, y, this.guiLeft, this.guiTop, this);
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,5 @@ public class DataRegistry {
|
||||
public static final Map<ResourceLocation, ControllerModel> CONTROLLERS = new HashMap<>();
|
||||
public static final Map<ResourceLocation, PortModel> PORTS = new HashMap<>();
|
||||
public static final Map<ResourceLocation, StructureModel> STRUCTURES = new HashMap<>();
|
||||
public static final Map<ResourceLocation, ProcessModel> PROCESSES = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ticticboooom.mods.mm.data;
|
||||
|
||||
import com.ticticboooom.mods.mm.process.PreProcessorType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessIngredientType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessOutputType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ProcessModel {
|
||||
public ResourceLocation structure;
|
||||
public int ticks;
|
||||
public Map<String, ProcessIngredientType.Value> inputs;
|
||||
public Map<String, ProcessOutputType.Value> outputs;
|
||||
public Map<String, PreProcessorType.Value> preprocessors;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ticticboooom.mods.mm.data.model;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.data.model.base.BlockstateModel;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
@@ -12,4 +14,5 @@ public class PortModel {
|
||||
public BlockstateModel defaultModel;
|
||||
public boolean showCutout;
|
||||
public boolean input;
|
||||
public JsonObject json;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class PortReloadListener extends JsonReloadListener {
|
||||
model.defaultModel = ParserUtils.parseOrDefault(json, "defaultModel", (x) -> ParserUtils.parseBlockState(x.getAsJsonObject()), BlockstateModel.DEFAULT);
|
||||
model.showCutout = ParserUtils.parseOrDefault(json, "showCutout", JsonElement::getAsBoolean, true);
|
||||
model.input = ParserUtils.parseOrDefault(json, "isInput", JsonElement::getAsBoolean, false);
|
||||
model.json = json;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.ticticboooom.mods.mm.data.reload;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.data.DataRegistry;
|
||||
import com.ticticboooom.mods.mm.data.ProcessModel;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.process.PreProcessorType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessIngredientType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessOutputType;
|
||||
import com.ticticboooom.mods.mm.setup.MMRegistries;
|
||||
import net.minecraft.client.resources.JsonReloadListener;
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||
import net.minecraftforge.event.world.PistonEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class ProcessReloadListener extends JsonReloadListener {
|
||||
public static final Gson GSON = new Gson();
|
||||
|
||||
public ProcessReloadListener() {
|
||||
super(GSON, "mm/processes");
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void on(AddReloadListenerEvent event) {
|
||||
event.addListener(new ProcessReloadListener());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) {
|
||||
for (Map.Entry<ResourceLocation, JsonElement> entry : objectIn.entrySet()) {
|
||||
DataRegistry.PROCESSES.put(entry.getKey(), parse(entry.getKey(), entry.getValue().getAsJsonObject()));
|
||||
}
|
||||
}
|
||||
|
||||
private ProcessModel parse(ResourceLocation res, JsonObject json) {
|
||||
ProcessModel model = new ProcessModel();
|
||||
model.structure = ParserUtils.parseOrDefault(json, "structure", x -> ResourceLocation.tryCreate(x.getAsString()), null);
|
||||
model.ticks = ParserUtils.parseOrDefault(json, "ticks", JsonElement::getAsInt, 0);
|
||||
model.inputs = ParserUtils.parseOrDefault(json, "inputs", x -> {
|
||||
JsonObject obj = x.getAsJsonObject();
|
||||
Map<String, ProcessIngredientType.Value> result = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
JsonObject inputObj = entry.getValue().getAsJsonObject();
|
||||
String type = inputObj.get("type").getAsString();
|
||||
ProcessIngredientType value = MMRegistries.PROCESS_INGREDIENT_TYPES.getValue(ResourceLocation.tryCreate(type));
|
||||
ProcessIngredientType.Value parse = value.parse(inputObj);
|
||||
result.put(entry.getKey(), parse);
|
||||
}
|
||||
return result;
|
||||
}, null);
|
||||
|
||||
model.outputs = ParserUtils.parseOrDefault(json, "outputs", x -> {
|
||||
JsonObject obj = x.getAsJsonObject();
|
||||
Map<String, ProcessOutputType.Value> result = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
JsonObject inputObj = entry.getValue().getAsJsonObject();
|
||||
String type = inputObj.get("type").getAsString();
|
||||
ProcessOutputType value = MMRegistries.PROCESS_OUTPUT_TYPES.getValue(ResourceLocation.tryCreate(type));
|
||||
ProcessOutputType.Value parse = value.parse(inputObj);
|
||||
result.put(entry.getKey(), parse);
|
||||
}
|
||||
return result;
|
||||
}, null);
|
||||
|
||||
model.preprocessors = ParserUtils.parseOrDefault(json, "preprocessors", x -> {
|
||||
JsonObject obj = x.getAsJsonObject();
|
||||
Map<String, PreProcessorType.Value> result = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
JsonObject inputObj = entry.getValue().getAsJsonObject();
|
||||
String type = inputObj.get("type").getAsString();
|
||||
PreProcessorType value = MMRegistries.PREPROCESSOR_TYPES.getValue(ResourceLocation.tryCreate(type));
|
||||
PreProcessorType.Value parse = value.parse(inputObj);
|
||||
parse.type = ResourceLocation.tryCreate(type);
|
||||
result.put(entry.getKey(), parse);
|
||||
}
|
||||
return result;
|
||||
}, null);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ticticboooom.mods.mm.inventory;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class ItemStackInventory implements IInventory {
|
||||
|
||||
private ItemStackHandler handler;
|
||||
|
||||
public ItemStackInventory(ItemStackHandler handler) {
|
||||
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return handler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int p_70301_1_) {
|
||||
return handler.getStackInSlot(p_70301_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
||||
ItemStack stackInSlot = handler.getStackInSlot(p_70298_1_);
|
||||
handler.setStackInSlot(p_70298_1_, ItemStack.EMPTY);
|
||||
return stackInSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int p_70304_1_) {
|
||||
return handler.getStackInSlot(p_70304_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
handler.setStackInSlot(p_70299_1_, p_70299_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer(PlayerEntity player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.ticticboooom.mods.mm.ports.base;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class MachineRecipeContext {
|
||||
private final List<PortStorage> inputs;
|
||||
private final List<PortStorage> outputs;
|
||||
private final ResourceLocation recipeId;
|
||||
private final String structureId;
|
||||
private final String controllerId;
|
||||
private final int ticks;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.ticticboooom.mods.mm.ports.base;
|
||||
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
|
||||
public abstract class OutputPortProcessor extends PortProcessor {
|
||||
public abstract boolean process(MachineProcessContext ctx);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ticticboooom.mods.mm.ports.base;
|
||||
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
|
||||
public abstract class PortProcessor {
|
||||
public abstract boolean canProcess(MachineRecipeContext ctx, PortStorage current);
|
||||
public abstract boolean process(MachineRecipeContext ctx, PortStorage current);
|
||||
public abstract boolean canProcess(MachineProcessContext ctx);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
package com.ticticboooom.mods.mm.ports.base;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.client.container.PortContainer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class PortStorage {
|
||||
public abstract <T> LazyOptional<T> getLazyOptional(Capability<T> cap, Direction direction);
|
||||
public abstract CompoundNBT save(CompoundNBT nbt);
|
||||
public abstract void load(CompoundNBT nbt);
|
||||
public abstract void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen);
|
||||
public void setupContainer(PortContainer container, PlayerInventory inv, TileEntity tile) {
|
||||
int playerOffsetX = 8;
|
||||
int playerOffsetY = 121;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
container.addSlot(new Slot(inv, 9 + (j * 9 + i), i* 18 + playerOffsetX, j* 18 + playerOffsetY));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
container.addSlot(new Slot(inv, i,8 + (i * 18), 179));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ticticboooom.mods.mm.ports.base;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.setup.MMTiles;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
@@ -8,17 +10,9 @@ import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class PortType extends ForgeRegistryEntry<PortType> {
|
||||
private final PortProcessor inputProcessorSupplier;
|
||||
private final PortProcessor outputProcessorSupplier;
|
||||
|
||||
public PortType(PortProcessor inputProcessor, PortProcessor outputProcessor) {
|
||||
this.inputProcessorSupplier = inputProcessor;
|
||||
this.outputProcessorSupplier = outputProcessor;
|
||||
}
|
||||
|
||||
public abstract PortStorage parseStorage(JsonObject data);
|
||||
public TileEntity createTileEntity() {
|
||||
return null;
|
||||
return MMTiles.PORT.get().create();
|
||||
}
|
||||
public abstract ResourceLocation getInputCutout();
|
||||
public abstract ResourceLocation getOutputCutout();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ticticboooom.mods.mm.ports.ctx;
|
||||
|
||||
import com.ticticboooom.mods.mm.data.ProcessModel;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineProcessContext {
|
||||
public ProcessModel processModel;
|
||||
public List<PortStorage> inputs;
|
||||
public List<PortStorage> outputs;
|
||||
public ResourceLocation processId;
|
||||
public ResourceLocation structureId;
|
||||
public int ticks;
|
||||
public int maxTicks;
|
||||
public MachineStructureContext structureCtx;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.ticticboooom.mods.mm.ports.ctx;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineStructureContext {
|
||||
public List<String> activeModifiers = new ArrayList<>();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.ticticboooom.mods.mm.ports.items;
|
||||
|
||||
import com.ticticboooom.mods.mm.ports.base.MachineRecipeContext;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortProcessor;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
|
||||
public class ItemPortInputProcessor extends PortProcessor {
|
||||
@Override
|
||||
public boolean canProcess(MachineRecipeContext ctx, PortStorage current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(MachineRecipeContext ctx, PortStorage current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.ticticboooom.mods.mm.ports.items;
|
||||
|
||||
import com.ticticboooom.mods.mm.ports.base.MachineRecipeContext;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortProcessor;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
|
||||
public class ItemPortOutputProcessor extends PortProcessor {
|
||||
@Override
|
||||
public boolean canProcess(MachineRecipeContext ctx, PortStorage current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(MachineRecipeContext ctx, PortStorage current) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,83 @@
|
||||
package com.ticticboooom.mods.mm.ports.items;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.client.container.PortContainer;
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class ItemPortStorage extends PortStorage {
|
||||
|
||||
|
||||
private final int rows;
|
||||
private final int columns;
|
||||
|
||||
public final LazyOptional<ItemStackHandler> itemStackHandlerLO;
|
||||
public final ItemStackHandler itemStackHandler;
|
||||
|
||||
public ItemPortStorage(int rows, int columns) {
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.itemStackHandler = new ItemStackHandler(this.rows * this.columns);
|
||||
itemStackHandlerLO = LazyOptional.of(() -> this.itemStackHandler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getLazyOptional(Capability<T> cap, Direction direction) {
|
||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return itemStackHandlerLO.cast();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
return null;
|
||||
CompoundNBT compoundNBT = new CompoundNBT();
|
||||
compoundNBT.put("items", itemStackHandler.serializeNBT());
|
||||
return compoundNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
CompoundNBT items = nbt.getCompound("items");
|
||||
itemStackHandler.deserializeNBT(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation(Ref.MOD_ID, "textures/gui/port_gui.png"));
|
||||
screen.blit(stack, left, top - 20, 0, 0, 175, 256);
|
||||
int offsetY = ((108 - (rows * 18)) / 2) + 10;
|
||||
int offsetX = ((162 - (columns * 18)) / 2) + 7;
|
||||
for (int y = 0; y < rows; y++) {
|
||||
for (int x = 0; x < columns; x++) {
|
||||
screen.blit(stack, left + (x * 18) + offsetX, top + (y * 18) + offsetY, 175, 256, 18, 18);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupContainer(PortContainer container, PlayerInventory inv, TileEntity tile) {
|
||||
int offsetX = ((162 - (columns * 18)) / 2) + 8;
|
||||
int offsetY = ((108 - (rows * 18)) / 2) + 11;
|
||||
ItemStackInventory items = new ItemStackInventory((ItemStackHandler) ((PortTile) tile).storage.getLazyOptional(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).orElse(null));
|
||||
for (int y = 0; y < rows; y++) {
|
||||
for (int x = 0; x < columns; x++) {
|
||||
container.addSlot(new Slot(items, (y * columns) + x, x * 18 + offsetX, y * 18 + offsetY));
|
||||
}
|
||||
}
|
||||
super.setupContainer(container, inv, tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ import com.ticticboooom.mods.mm.ports.base.PortType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ItemPortType extends PortType {
|
||||
public ItemPortType() {
|
||||
super(new ItemPortInputProcessor(), new ItemPortOutputProcessor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortStorage parseStorage(JsonObject data) {
|
||||
int rows = data.get("rows").getAsInt();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ticticboooom.mods.mm.process;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
public abstract class ModifierAction extends ForgeRegistryEntry<ModifierAction> {
|
||||
|
||||
public abstract Value parse(JsonObject json);
|
||||
public abstract boolean modify(Value val, MachineProcessContext ctx);
|
||||
|
||||
public static class Value {
|
||||
public ResourceLocation type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ticticboooom.mods.mm.process;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
public abstract class PreProcessorType extends ForgeRegistryEntry<PreProcessorType> {
|
||||
public abstract Value parse(JsonObject json);
|
||||
public abstract boolean process(Value val, MachineProcessContext ctx);
|
||||
|
||||
public static class Value {
|
||||
public ResourceLocation type;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticticboooom.mods.mm.process;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
public abstract class ProcessIngredientType extends ForgeRegistryEntry<ProcessIngredientType> {
|
||||
public abstract Value parse(JsonObject object);
|
||||
public abstract boolean canProcess(Value val, MachineProcessContext ctx);
|
||||
public abstract void process(Value val, MachineProcessContext ctx);
|
||||
|
||||
public abstract static class Value {
|
||||
public Value(ResourceLocation type) {
|
||||
this.type = type;
|
||||
}
|
||||
public ResourceLocation type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticticboooom.mods.mm.process;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
public abstract class ProcessOutputType extends ForgeRegistryEntry<ProcessOutputType> {
|
||||
public abstract Value parse(JsonObject object);
|
||||
public abstract boolean canProcess(Value val, MachineProcessContext ctx);
|
||||
public abstract void process(Value val, MachineProcessContext ctx);
|
||||
|
||||
public abstract static class Value {
|
||||
public Value(ResourceLocation type) {
|
||||
this.type = type;
|
||||
}
|
||||
public ResourceLocation type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ticticboooom.mods.mm.process.ingredients;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.items.ItemPortStorage;
|
||||
import com.ticticboooom.mods.mm.process.ProcessIngredientType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ItemsIngredientType extends ProcessIngredientType {
|
||||
@Override
|
||||
public Value parse(JsonObject object) {
|
||||
ItemsValue itemsValue = new ItemsValue(this.getRegistryName());
|
||||
itemsValue.item = ParserUtils.parseOrDefault(object, "item", x -> ResourceLocation.tryCreate(x.getAsString()), null);
|
||||
itemsValue.amount = ParserUtils.parseOrDefault(object, "amount", JsonElement::getAsInt, 1);
|
||||
return itemsValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProcess(Value val, MachineProcessContext ctx) {
|
||||
ItemsValue ival = (ItemsValue) val;
|
||||
int validCount = 0;
|
||||
for (PortStorage input : ctx.inputs) {
|
||||
if (input instanceof ItemPortStorage) {
|
||||
ItemPortStorage items = (ItemPortStorage) input;
|
||||
for (int i = 0; i < items.itemStackHandler.getSlots(); i++) {
|
||||
ItemStack stackInSlot = items.itemStackHandler.getStackInSlot(i);
|
||||
if (stackInSlot.getItem().getRegistryName().equals(ival.item)) {
|
||||
validCount += stackInSlot.getCount();
|
||||
}
|
||||
}
|
||||
if (validCount >= ival.amount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Value val, MachineProcessContext ctx) {
|
||||
ItemsValue ival = (ItemsValue) val;
|
||||
int countLeft = ival.amount;
|
||||
for (PortStorage input : ctx.inputs) {
|
||||
if (input instanceof ItemPortStorage) {
|
||||
ItemPortStorage items = (ItemPortStorage) input;
|
||||
for (int i = 0; i < items.itemStackHandler.getSlots(); i++) {
|
||||
ItemStack stackInSlot = items.itemStackHandler.getStackInSlot(i);
|
||||
if (stackInSlot.getItem().getRegistryName().equals(ival.item)) {
|
||||
items.itemStackHandler.extractItem(i, countLeft, false);
|
||||
countLeft -= stackInSlot.getCount();
|
||||
}
|
||||
if (countLeft <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class ItemsValue extends Value {
|
||||
public ResourceLocation item;
|
||||
public int amount;
|
||||
|
||||
public ItemsValue(ResourceLocation type) {
|
||||
super(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ticticboooom.mods.mm.process.modifieractions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.process.ModifierAction;
|
||||
|
||||
public class NothingModifierAction extends ModifierAction {
|
||||
@Override
|
||||
public Value parse(JsonObject json) {
|
||||
return new NothingValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modify(Value val, MachineProcessContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class NothingValue extends Value {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ticticboooom.mods.mm.process.modifieractions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.process.ModifierAction;
|
||||
|
||||
public class SpeedModifierAction extends ModifierAction {
|
||||
@Override
|
||||
public Value parse(JsonObject json) {
|
||||
SpeedValue speedValue = new SpeedValue();
|
||||
speedValue.percentageDifference = json.get("ticks").getAsDouble();
|
||||
return speedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modify(Value val, MachineProcessContext ctx) {
|
||||
SpeedValue speed = (SpeedValue) val;
|
||||
ctx.ticks *= speed.percentageDifference;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final class SpeedValue extends Value {
|
||||
public Double percentageDifference;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.ticticboooom.mods.mm.process.outputs;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.ports.base.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.items.ItemPortStorage;
|
||||
import com.ticticboooom.mods.mm.process.ProcessOutputType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class ItemsOutputType extends ProcessOutputType {
|
||||
@Override
|
||||
public Value parse(JsonObject object) {
|
||||
ItemsValue itemsValue = new ItemsValue(this.getRegistryName());
|
||||
itemsValue.item = ParserUtils.parseOrDefault(object, "item", x -> ResourceLocation.tryCreate(x.getAsString()), null);
|
||||
itemsValue.amount = ParserUtils.parseOrDefault(object, "amount", JsonElement::getAsInt, 1);
|
||||
return itemsValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProcess(Value val, MachineProcessContext ctx) {
|
||||
ItemsOutputType.ItemsValue ival = (ItemsOutputType.ItemsValue) val;
|
||||
int validCount = ival.amount;
|
||||
for (PortStorage output : ctx.outputs) {
|
||||
if (output instanceof ItemPortStorage) {
|
||||
ItemPortStorage items = (ItemPortStorage) output;
|
||||
for (int i = 0; i < items.itemStackHandler.getSlots(); i++) {
|
||||
ItemStack stackInSlot = items.itemStackHandler.getStackInSlot(i);
|
||||
if (stackInSlot.getItem().getRegistryName().equals(ival.item)) {
|
||||
validCount -= stackInSlot.getMaxStackSize() - stackInSlot.getCount();
|
||||
} else if (stackInSlot.isEmpty()) {
|
||||
validCount -= new ItemStack(ForgeRegistries.ITEMS.getValue(ival.item)).getMaxStackSize();
|
||||
}
|
||||
}
|
||||
if (validCount <= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Value val, MachineProcessContext ctx) {
|
||||
ItemsOutputType.ItemsValue ival = (ItemsOutputType.ItemsValue) val;
|
||||
int validCount = ival.amount;
|
||||
for (PortStorage output : ctx.outputs) {
|
||||
if (output instanceof ItemPortStorage) {
|
||||
ItemPortStorage items = (ItemPortStorage) output;
|
||||
for (int i = 0; i < items.itemStackHandler.getSlots(); i++) {
|
||||
ItemStack stackInSlot = items.itemStackHandler.getStackInSlot(i);
|
||||
if (stackInSlot.getItem().getRegistryName().equals(ival.item)) {
|
||||
int diff = stackInSlot.getMaxStackSize() - stackInSlot.getCount();
|
||||
int relamount = Math.min(diff, validCount);
|
||||
items.itemStackHandler.insertItem(i, new ItemStack(stackInSlot.getItem(), relamount), false);
|
||||
validCount -= relamount;
|
||||
} else if (stackInSlot.isEmpty()) {
|
||||
int maxStackSize = new ItemStack(ForgeRegistries.ITEMS.getValue(ival.item)).getMaxStackSize();
|
||||
int relamount = Math.min(maxStackSize, validCount);
|
||||
items.itemStackHandler.insertItem(i, new ItemStack(ForgeRegistries.ITEMS.getValue(ival.item), relamount), false);
|
||||
validCount -= relamount;
|
||||
}
|
||||
if (validCount <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ItemsValue extends Value {
|
||||
public ResourceLocation item;
|
||||
public int amount;
|
||||
|
||||
public ItemsValue(ResourceLocation type) {
|
||||
super(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ticticboooom.mods.mm.process.preprocessors;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineProcessContext;
|
||||
import com.ticticboooom.mods.mm.process.ModifierAction;
|
||||
import com.ticticboooom.mods.mm.process.PreProcessorType;
|
||||
import com.ticticboooom.mods.mm.setup.MMRegistries;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModifiablePreProcessorType extends PreProcessorType {
|
||||
@Override
|
||||
public Value parse(JsonObject json) {
|
||||
ModifiableValue result = new ModifiableValue();
|
||||
result.results = new HashMap<>();
|
||||
JsonObject modifierResults = json.get("modifier_results").getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> entry : modifierResults.entrySet()) {
|
||||
JsonObject obj = entry.getValue().getAsJsonObject();
|
||||
String type = obj.get("type").getAsString();
|
||||
ModifierAction value = MMRegistries.MODIFIER_ACTIONS.getValue(ResourceLocation.tryCreate(type));
|
||||
ModifierAction.Value parse = value.parse(obj);
|
||||
parse.type = ResourceLocation.tryCreate(type);
|
||||
result.results.put(entry.getKey(), parse);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Value val, MachineProcessContext ctx) {
|
||||
ModifiableValue mval = (ModifiableValue) val;
|
||||
List<String> modifiers = ctx.structureCtx.activeModifiers;
|
||||
for (String entry : modifiers) {
|
||||
ModifierAction.Value maVal = ((ModifiableValue) val).results.get(entry);
|
||||
ModifierAction value = MMRegistries.MODIFIER_ACTIONS.getValue(maVal.type);
|
||||
if (!value.modify(maVal, ctx)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class ModifiableValue extends Value {
|
||||
public Map<String, ModifierAction.Value> results;
|
||||
public String name;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.ControllerBlock;
|
||||
import com.ticticboooom.mods.mm.block.PortBlock;
|
||||
import com.ticticboooom.mods.mm.client.container.ControllerContainer;
|
||||
import com.ticticboooom.mods.mm.client.container.PortContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
@@ -15,4 +16,5 @@ public class MMContainerTypes {
|
||||
public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, Ref.MOD_ID);
|
||||
|
||||
public static final RegistryObject<ContainerType<ControllerContainer>> CONTROLLER = CONTAINERS.register("controller", () -> IForgeContainerType.create(ControllerContainer::new));
|
||||
public static final RegistryObject<ContainerType<PortContainer>> PORT = CONTAINERS.register("port", () -> IForgeContainerType.create(PortContainer::new));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
package com.ticticboooom.mods.mm.setup;
|
||||
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.process.ModifierAction;
|
||||
import com.ticticboooom.mods.mm.process.PreProcessorType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessIngredientType;
|
||||
import com.ticticboooom.mods.mm.process.ProcessOutputType;
|
||||
import com.ticticboooom.mods.mm.process.ingredients.ItemsIngredientType;
|
||||
import com.ticticboooom.mods.mm.process.modifieractions.NothingModifierAction;
|
||||
import com.ticticboooom.mods.mm.process.modifieractions.SpeedModifierAction;
|
||||
import com.ticticboooom.mods.mm.process.outputs.ItemsOutputType;
|
||||
import com.ticticboooom.mods.mm.process.preprocessors.ModifiablePreProcessorType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.keys.*;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
@@ -13,14 +22,22 @@ import net.minecraftforge.registries.RegistryBuilder;
|
||||
public class MMRegistries {
|
||||
|
||||
public static IForgeRegistry<StructureKeyType> STRUCTURE_KEY_TYPES;
|
||||
public static IForgeRegistry<ProcessIngredientType> PROCESS_INGREDIENT_TYPES;
|
||||
public static IForgeRegistry<ProcessOutputType> PROCESS_OUTPUT_TYPES;
|
||||
public static IForgeRegistry<PreProcessorType> PREPROCESSOR_TYPES;
|
||||
public static IForgeRegistry<ModifierAction> MODIFIER_ACTIONS;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void on(RegistryEvent.NewRegistry event) {
|
||||
STRUCTURE_KEY_TYPES = new RegistryBuilder<StructureKeyType>().setName(Ref.Reg.STRUCTURE_KEY_TYPE).setType(StructureKeyType.class).create();
|
||||
PROCESS_INGREDIENT_TYPES = new RegistryBuilder<ProcessIngredientType>().setName(Ref.Reg.PROCESS_INGREDIENT_TYPE).setType(ProcessIngredientType.class).create();
|
||||
PROCESS_OUTPUT_TYPES = new RegistryBuilder<ProcessOutputType>().setName(Ref.Reg.PROCESS_OUTPUT_TYPE).setType(ProcessOutputType.class).create();
|
||||
PREPROCESSOR_TYPES = new RegistryBuilder<PreProcessorType>().setName(Ref.Reg.PREPROCESSOR_TYPE).setType(PreProcessorType.class).create();
|
||||
MODIFIER_ACTIONS = new RegistryBuilder<ModifierAction>().setName(Ref.Reg.MODIFIER_ACTIONS).setType(ModifierAction.class).create();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<StructureKeyType> event) {
|
||||
public static void registerSKT(RegistryEvent.Register<StructureKeyType> event) {
|
||||
event.getRegistry().registerAll(
|
||||
new BlockStructureKeyType().setRegistryName(Ref.Reg.SKT.BLOCK),
|
||||
new PortStructureKeyType().setRegistryName(Ref.Reg.SKT.PORT),
|
||||
@@ -29,4 +46,33 @@ public class MMRegistries {
|
||||
new ModifiableStructureKeyType().setRegistryName(Ref.Reg.SKT.MODIFIABLE)
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPIT(RegistryEvent.Register<ProcessIngredientType> event) {
|
||||
event.getRegistry().registerAll(
|
||||
new ItemsIngredientType().setRegistryName(Ref.Reg.PIT.ITEMS)
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPOT(RegistryEvent.Register<ProcessOutputType> event) {
|
||||
event.getRegistry().registerAll(
|
||||
new ItemsOutputType().setRegistryName(Ref.Reg.POT.ITEMS)
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPT(RegistryEvent.Register<PreProcessorType> event) {
|
||||
event.getRegistry().registerAll(
|
||||
new ModifiablePreProcessorType().setRegistryName(Ref.Reg.PT.MODIFIABLE)
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerMA(RegistryEvent.Register<ModifierAction> event) {
|
||||
event.getRegistry().registerAll(
|
||||
new NothingModifierAction().setRegistryName(Ref.Reg.MA.NOTHING),
|
||||
new SpeedModifierAction().setRegistryName(Ref.Reg.MA.SPEED)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ticticboooom.mods.mm.structures;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -13,5 +14,5 @@ import java.util.List;
|
||||
public abstract class StructureKeyType extends ForgeRegistryEntry<StructureKeyType> {
|
||||
public abstract boolean matches(JsonElement json);
|
||||
public abstract StructureKeyTypeValue parse(JsonElement json, List<ResourceLocation> controllerIds, ResourceLocation structureId);
|
||||
public abstract boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world);
|
||||
public abstract boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -60,7 +61,7 @@ public class BlockStructureKeyType extends StructureKeyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world) {
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx) {
|
||||
BlockStructureKeyType.Value data = (BlockStructureKeyType.Value) dataIn;
|
||||
boolean matches = false;
|
||||
for (String s : data.blockSelector) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.setup.MMRegistries;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
@@ -13,6 +14,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -47,11 +49,12 @@ public class ModifiableStructureKeyType extends StructureKeyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world) {
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx) {
|
||||
ModifiableStructureKeyType.Value data = (ModifiableStructureKeyType.Value) dataIn;
|
||||
for (Map.Entry<String, StructureModel.Key> entry : data.modifiers.entrySet()) {
|
||||
StructureKeyType value = MMRegistries.STRUCTURE_KEY_TYPES.getValue(entry.getValue().type);
|
||||
if (value.isValidPlacement(pos, model, state, entry.getValue().data, world)) {
|
||||
if (value.isValidPlacement(pos, model, state, entry.getValue().data, world, ctx)) {
|
||||
ctx.activeModifiers.add(entry.getKey());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
||||
import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -33,15 +34,18 @@ public class PortGroupStructureKeyType extends StructureKeyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world) {
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx) {
|
||||
PortGroupStructureKeyType.Value data = (PortGroupStructureKeyType.Value) dataIn;
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof PortTile) {
|
||||
PortTile pte = (PortTile) te;
|
||||
if (pte.portModel == null || pte.portModel.id == null) {
|
||||
return false;
|
||||
}
|
||||
List<String> reqKeys = model.portGroupings.get(data.group);
|
||||
for (String reqKey : reqKeys) {
|
||||
StructureModel.RequiredPort requiredPort = model.requiredPorts.get(reqKey);
|
||||
if (requiredPort != null && !requiredPort.port.equals(pte.portModel.type)) {
|
||||
if (requiredPort != null && requiredPort.port != null && !requiredPort.port.equals(pte.portModel.type)) {
|
||||
return false;
|
||||
}
|
||||
boolean matches = false;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.setup.MMBlocks;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
@@ -36,12 +37,15 @@ public class PortStructureKeyType extends StructureKeyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world) {
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx) {
|
||||
PortStructureKeyType.Value data = (PortStructureKeyType.Value) dataIn;
|
||||
if (state.getBlock().getRegistryName().equals(MMBlocks.PORT.getId())) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof PortTile) {
|
||||
PortTile pte = (PortTile) te;
|
||||
if (pte.portModel == null || pte.portModel.id == null) {
|
||||
return false;
|
||||
}
|
||||
boolean io = true;
|
||||
if (data.input.isPresent()) {
|
||||
io = data.input.get() == pte.portModel.input;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ticticboooom.mods.mm.Ref;
|
||||
import com.ticticboooom.mods.mm.block.tile.PortTile;
|
||||
import com.ticticboooom.mods.mm.data.model.StructureModel;
|
||||
import com.ticticboooom.mods.mm.data.util.ParserUtils;
|
||||
import com.ticticboooom.mods.mm.ports.ctx.MachineStructureContext;
|
||||
import com.ticticboooom.mods.mm.setup.MMBlocks;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyType;
|
||||
import com.ticticboooom.mods.mm.structures.StructureKeyTypeValue;
|
||||
@@ -36,12 +37,15 @@ public class PortTierStructureKeyType extends StructureKeyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world) {
|
||||
public boolean isValidPlacement(BlockPos pos, StructureModel model, BlockState state, StructureKeyTypeValue dataIn, World world, MachineStructureContext ctx) {
|
||||
PortTierStructureKeyType.Value data = (PortTierStructureKeyType.Value) dataIn;
|
||||
if (state.getBlock().getRegistryName().equals(MMBlocks.PORT.getId())) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof PortTile) {
|
||||
PortTile pte = (PortTile) te;
|
||||
if (pte.portModel == null || pte.portModel.id == null) {
|
||||
return false;
|
||||
}
|
||||
boolean io = true;
|
||||
if (data.input.isPresent()) {
|
||||
io = data.input.get() == pte.portModel.input;
|
||||
|
||||
@@ -6,5 +6,7 @@
|
||||
"block": "minecraft:sponge",
|
||||
"properties": {}
|
||||
},
|
||||
"rows": 2,
|
||||
"columns": 2,
|
||||
"isInput": true
|
||||
}
|
||||
@@ -6,5 +6,7 @@
|
||||
"block": "minecraft:sponge",
|
||||
"properties": {}
|
||||
},
|
||||
"rows": 2,
|
||||
"columns": 2,
|
||||
"isInput": false
|
||||
}
|
||||
@@ -1,7 +1,22 @@
|
||||
{
|
||||
"structure": "test:mystructure",
|
||||
"ticks": 100,
|
||||
"inputs": {
|
||||
"firstboi": {
|
||||
"myitem": {
|
||||
"type": "mm:items",
|
||||
"item": "minecraft:glass",
|
||||
"amount": 10
|
||||
}
|
||||
},
|
||||
"outputs": {
|
||||
"myout": {
|
||||
"type": "mm:items",
|
||||
"item": "minecraft:coal",
|
||||
"amount": 23
|
||||
}
|
||||
},
|
||||
"preprocessors": {
|
||||
"mypp": {
|
||||
"type": "mm:modifiable",
|
||||
"modifier_results": {
|
||||
"starter": {
|
||||
@@ -9,11 +24,7 @@
|
||||
},
|
||||
"basic": {
|
||||
"type": "mm:speed",
|
||||
"ticks": "-10%"
|
||||
},
|
||||
"intermediate": {
|
||||
"type": "mm:chance",
|
||||
"chance": "+10%"
|
||||
"ticks": 0.01
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Sun Apr 17 16:51:18 BST 2022
|
||||
VERSION_CODE=1589
|
||||
#Mon Apr 18 11:29:54 BST 2022
|
||||
VERSION_CODE=1736
|
||||
|
||||
Reference in New Issue
Block a user