mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-03-18 21:40:34 +01:00
initial CF beta release
This commit is contained in:
10
build.gradle
10
build.gradle
@@ -119,6 +119,10 @@ minecraft {
|
||||
// Include resources generated by data generators.
|
||||
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||
|
||||
|
||||
repositories {
|
||||
maven { url 'https://modmaven.dev/' }
|
||||
}
|
||||
dependencies {
|
||||
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
|
||||
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
|
||||
@@ -127,6 +131,12 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.18'
|
||||
minecraft 'net.minecraftforge:forge:1.16.5-36.1.16'
|
||||
implementation 'com.github.marschall:memoryfilesystem:2.1.0'
|
||||
|
||||
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core
|
||||
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:additions")// Mekanism: Additions
|
||||
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")// Mekanism: Generators
|
||||
runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:tools")// Mekanism: Tools
|
||||
|
||||
// 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"
|
||||
|
||||
@@ -4,7 +4,20 @@
|
||||
{
|
||||
"type": "masterfulmachinery:items",
|
||||
"data": {
|
||||
"slots": 18
|
||||
"rows": 3,
|
||||
"columns": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "masterfulmachinery:energy",
|
||||
"data": {
|
||||
"capacity": 30000
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "masterfulmachinery:fluids",
|
||||
"data": {
|
||||
"capacity": 10000
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
org.gradle.daemon=false
|
||||
mekanism_version=1.16.5-10.0.20.447
|
||||
@@ -12,6 +12,8 @@ import com.ticticboooom.mods.mm.datagen.MMPackFinder;
|
||||
import com.ticticboooom.mods.mm.datagen.MemoryDataGeneratorFactory;
|
||||
import com.ticticboooom.mods.mm.datagen.PackType;
|
||||
import com.ticticboooom.mods.mm.datagen.gen.MMBlockStateProvider;
|
||||
import com.ticticboooom.mods.mm.datagen.gen.MMItemModelProvider;
|
||||
import com.ticticboooom.mods.mm.network.PacketHandler;
|
||||
import com.ticticboooom.mods.mm.registration.MMLoader;
|
||||
import com.ticticboooom.mods.mm.registration.MMPorts;
|
||||
import com.ticticboooom.mods.mm.registration.RecipeTypes;
|
||||
@@ -51,6 +53,7 @@ public class MM {
|
||||
MMPorts.init();
|
||||
MMLoader.load();
|
||||
MemoryDataGeneratorFactory.init();
|
||||
PacketHandler.init();
|
||||
registerDataGen();
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
MMLoader.BLOCKS_REG.register(bus);
|
||||
@@ -70,6 +73,7 @@ public class MM {
|
||||
ExistingFileHelper existingFileHelper = new ExistingFileHelper(ImmutableList.of(), ImmutableSet.of(), false);
|
||||
|
||||
generator.addProvider(new MMBlockStateProvider(generator, existingFileHelper));
|
||||
generator.addProvider(new MMItemModelProvider(generator, existingFileHelper));
|
||||
}
|
||||
|
||||
public static void generate() {
|
||||
@@ -92,8 +96,8 @@ public class MM {
|
||||
for (RegistryObject<ContainerType<ControllerBlockContainer>> container : MMLoader.CONTAINERS) {
|
||||
ScreenManager.register(container.get(), ControllerBlockContainerScreen::new);
|
||||
}
|
||||
for (RegistryObject<ContainerType<PortBlockContainer>> container : MMLoader.PORT_CONTAINERS) {
|
||||
ScreenManager.register(container.get(), PortBlockContainerScreen::new);
|
||||
for (RegistryObject<ContainerType<?>> container : MMLoader.PORT_CONTAINERS) {
|
||||
ScreenManager.register((ContainerType<PortBlockContainer>) container.get(), PortBlockContainerScreen::new);
|
||||
}
|
||||
for (RegistryObject<ControllerBlock> block : MMLoader.BLOCKS) {
|
||||
RenderTypeLookup.setRenderLayer(block.get(), layer -> layer == RenderType.solid() || layer == RenderType.translucent());
|
||||
|
||||
@@ -4,13 +4,17 @@ import com.ticticboooom.mods.mm.block.tile.ControllerBlockEntity;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DirectionalBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
@@ -22,7 +26,7 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ControllerBlock extends Block {
|
||||
public class ControllerBlock extends DirectionalBlock {
|
||||
|
||||
private RegistryObject<TileEntityType<?>> type;
|
||||
|
||||
@@ -31,6 +35,18 @@ public class ControllerBlock extends Block {
|
||||
.harvestLevel(1)
|
||||
.harvestTool(ToolType.PICKAXE));
|
||||
this.type = type;
|
||||
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
|
||||
super.createBlockStateDefinition(builder.add(DirectionalBlock.FACING));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext ctx) {
|
||||
return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
package com.ticticboooom.mods.mm.block;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.ControllerBlockEntity;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
import com.ticticboooom.mods.mm.ports.storage.ItemPortStorage;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
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.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -29,4 +47,28 @@ public class MachinePortBlock extends Block {
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return type.get().create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType use(BlockState state, World level, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult traceResult) {
|
||||
if (!level.isClientSide()) {
|
||||
TileEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof MachinePortBlockEntity) {
|
||||
NetworkHooks.openGui(((ServerPlayerEntity) player), (MachinePortBlockEntity)blockEntity, pos);
|
||||
}
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, World world, BlockPos pos, BlockState state1, boolean p_196243_5_) {
|
||||
TileEntity tile = world.getBlockEntity(pos);
|
||||
if (tile instanceof MachinePortBlockEntity){
|
||||
Object o = ((MachinePortBlockEntity) tile).getStorage().getLO().orElse(null);
|
||||
if (o instanceof ItemStackHandler) {
|
||||
InventoryHelper.dropContents(world, pos, new ItemStackInventory((ItemStackHandler) o));
|
||||
}
|
||||
}
|
||||
super.onRemove(state, world, pos, state1, p_196243_5_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,33 @@ package com.ticticboooom.mods.mm.block.container;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.tile.ControllerBlockEntity;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PortBlockContainer extends Container {
|
||||
|
||||
private final PlayerInventory inv;
|
||||
@Getter
|
||||
private MachinePortBlockEntity tile;
|
||||
|
||||
protected PortBlockContainer(@Nullable ContainerType<?> p_i50105_1_, int windowId, MachinePortBlockEntity tile) {
|
||||
public PortBlockContainer(@Nullable ContainerType<?> p_i50105_1_, int windowId, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
super(p_i50105_1_, windowId);
|
||||
this.inv = inv;
|
||||
tile.getStorage().setupContainer(this, inv, tile);
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public PortBlockContainer(ContainerType<?> container, int windowId, PlayerInventory player, PacketBuffer buf) {
|
||||
this(container, windowId, (MachinePortBlockEntity) player.player.level.getBlockEntity(buf.readBlockPos()));
|
||||
this(container, windowId, player, (MachinePortBlockEntity) player.player.level.getBlockEntity(buf.readBlockPos()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,5 +36,36 @@ public class PortBlockContainer extends Container {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot addSlot(Slot p_75146_1_) {
|
||||
return super.addSlot(p_75146_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(PlayerEntity p_82846_1_, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Object o = tile.getStorage().getLO().orElse(null);
|
||||
if (o instanceof ItemStackHandler) {
|
||||
ItemStackHandler handler = ((ItemStackHandler) o);
|
||||
Slot slot = this.getSlot(index);
|
||||
if (slot.hasItem()) {
|
||||
ItemStack itemStack1 = slot.getItem();
|
||||
itemStack = itemStack1.copy();
|
||||
if (index < handler.getSlots()) {
|
||||
if (!this.moveItemStackTo(itemStack1, handler.getSlots(), inv.getContainerSize(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.moveItemStackTo(itemStack1, 0, handler.getSlots(), false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack1.isEmpty()) {
|
||||
slot.set(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.setChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,18 @@ import com.ticticboooom.mods.mm.block.container.ControllerBlockContainer;
|
||||
import com.ticticboooom.mods.mm.data.MachineProcessRecipe;
|
||||
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
|
||||
import com.ticticboooom.mods.mm.model.ProcessUpdate;
|
||||
import com.ticticboooom.mods.mm.network.PacketHandler;
|
||||
import com.ticticboooom.mods.mm.network.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import com.ticticboooom.mods.mm.registration.RecipeTypes;
|
||||
import lombok.Getter;
|
||||
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.ContainerType;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -19,6 +23,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
@@ -76,9 +81,11 @@ public class ControllerBlockEntity extends TileEntity implements ITickableTileEn
|
||||
List<MachineProcessRecipe> processRecipes = level.getRecipeManager().getAllRecipesFor(RecipeTypes.MACHINE_PROCESS);
|
||||
for (MachineProcessRecipe recipe : processRecipes) {
|
||||
if (recipe.matches(inputPorts, structure.getStructureId())) {
|
||||
ProcessUpdate update = recipe.process(inputPorts, outputPorts, this.update);
|
||||
this.update = update;
|
||||
this.update = recipe.process(inputPorts, outputPorts, this.update);
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(worldPosition, save(new CompoundNBT())));
|
||||
return;
|
||||
} else {
|
||||
this.update.setTicksTaken(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,4 +101,18 @@ public class ControllerBlockEntity extends TileEntity implements ITickableTileEn
|
||||
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
|
||||
return new ControllerBlockContainer(container.get(), p_createMenu_1_, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
nbt.putInt("ticks", update.getTicksTaken());
|
||||
nbt.putString("msg", update.getMsg());
|
||||
return super.save(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(BlockState p_230337_1_, CompoundNBT nbt) {
|
||||
super.load(p_230337_1_, nbt);
|
||||
update.setTicksTaken(nbt.getInt("ticks"));
|
||||
update.setMsg(nbt.getString("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,42 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.network.PacketHandler;
|
||||
import com.ticticboooom.mods.mm.network.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import lombok.Getter;
|
||||
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.ContainerType;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
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 net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MachinePortBlockEntity extends TileEntity {
|
||||
public class MachinePortBlockEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
|
||||
|
||||
private ContainerType<?> container;
|
||||
@Getter
|
||||
private IPortStorage storage;
|
||||
@Getter
|
||||
private boolean input;
|
||||
|
||||
|
||||
public MachinePortBlockEntity(TileEntityType<?> p_i48289_1_, IPortStorage storage, boolean input) {
|
||||
public MachinePortBlockEntity(TileEntityType<?> p_i48289_1_, ContainerType<?> container, IPortStorage storage, boolean input) {
|
||||
super(p_i48289_1_);
|
||||
this.container = container;
|
||||
this.storage = storage;
|
||||
this.input = input;
|
||||
}
|
||||
@@ -34,4 +49,32 @@ public class MachinePortBlockEntity extends TileEntity {
|
||||
}
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
nbt.put("inv", storage.save(new CompoundNBT()));
|
||||
return super.save(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(BlockState state, CompoundNBT nbt) {
|
||||
super.load(state, nbt);
|
||||
storage.load(nbt.getCompound("inv"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new StringTextComponent("Port");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int windowsId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PortBlockContainer(container, windowsId, inv,this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(worldPosition, save(new CompoundNBT())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,17 +10,24 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class PortBlockContainerScreen extends ContainerScreen<PortBlockContainer> {
|
||||
public PortBlockContainerScreen(PortBlockContainer p_i51105_1_, PlayerInventory p_i51105_2_, ITextComponent p_i51105_3_) {
|
||||
super(p_i51105_1_, p_i51105_2_, p_i51105_3_);
|
||||
private final PortBlockContainer container;
|
||||
|
||||
public PortBlockContainerScreen(PortBlockContainer container, PlayerInventory p_i51105_2_, ITextComponent p_i51105_3_) {
|
||||
super(container, p_i51105_2_, p_i51105_3_);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
private static final ResourceLocation GUI = new ResourceLocation(MM.ID, "textures/gui/gui_large.png");
|
||||
private static final ResourceLocation GUI = new ResourceLocation(MM.ID, "textures/gui/port_gui.png");
|
||||
|
||||
@Override
|
||||
protected void renderBg(MatrixStack stack, float p_230450_2_, int p_230450_3_, int p_230450_4_) {
|
||||
protected void renderBg(MatrixStack stack, float p_230450_2_, int mouseX, int mouseY) {
|
||||
this.renderBackground(stack);
|
||||
this.minecraft.textureManager.bind(GUI);
|
||||
this.blit(stack, this.leftPos, this.topPos, 0, 0, this.width, this.height);
|
||||
container.getTile().getStorage().render(stack, mouseX, mouseY, this.leftPos, this.topPos, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(MatrixStack stack, int p_230451_2_, int p_230451_3_) {
|
||||
drawString(stack, this.minecraft.font, container.getTile().getDisplayName(), 7, 5, 0xfefefe);
|
||||
drawString(stack, this.minecraft.font, "Inventory", 7, 130, 0xfefefe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.ticticboooom.mods.mm.client.util;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidRenderer {
|
||||
|
||||
public static final FluidRenderer INSTANCE = new FluidRenderer(1000, 16, 16, 16);
|
||||
private static final int TEX_WIDTH = 16;
|
||||
private static final int TEX_HEIGHT = 16;
|
||||
|
||||
private int capacity;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int minHeight;
|
||||
|
||||
public FluidRenderer(int capacity, int width, int height, int minHeight) {
|
||||
this.capacity = capacity;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.minHeight = minHeight;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrixStack, final int xPosition, final int yPosition, FluidStack stack, final int height) {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableAlphaTest();
|
||||
|
||||
drawFluid(matrixStack, xPosition, yPosition, stack, height);
|
||||
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
|
||||
RenderSystem.disableAlphaTest();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
private void drawFluid(MatrixStack matrixStack, int xPosition, int yPosition, FluidStack stack, final int height) {
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
Fluid fluid = stack.getFluid();
|
||||
if (fluid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextureAtlasSprite fluidStillSprite = getStillFluidSprite(stack);
|
||||
|
||||
FluidAttributes attributes = fluid.getAttributes();
|
||||
int fluidColor = attributes.getColor(stack);
|
||||
|
||||
int amount = stack.getAmount();
|
||||
|
||||
drawTiledSprite(matrixStack, xPosition, yPosition, width, height, fluidColor, height, fluidStillSprite);
|
||||
}
|
||||
|
||||
private void drawTiledSprite(MatrixStack matrixStack, int xPosition, int yPosition, int width, int height, int color, int scaledAmount, TextureAtlasSprite sprite) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
minecraft.getTextureManager().bind(PlayerContainer.BLOCK_ATLAS);
|
||||
Matrix4f matrix = matrixStack.last().pose();
|
||||
setGLColorFromInt(color);
|
||||
|
||||
final int xTileCount = width / TEX_WIDTH;
|
||||
final int xRemainder = height - (xTileCount * TEX_WIDTH);
|
||||
final int yTileCount = scaledAmount / TEX_HEIGHT;
|
||||
final int yRemainder = scaledAmount - (yTileCount * TEX_HEIGHT);
|
||||
|
||||
final int yStart = yPosition + height;
|
||||
|
||||
for (int xTile = 0; xTile <= xTileCount; xTile++) {
|
||||
for (int yTile = 0; yTile <= yTileCount; yTile++) {
|
||||
int w = (xTile == xTileCount) ? xRemainder : TEX_WIDTH;
|
||||
int h = (yTile == yTileCount) ? yRemainder : TEX_HEIGHT;
|
||||
int x = xPosition + (xTile * TEX_WIDTH);
|
||||
int y = yStart - ((yTile + 1) * TEX_HEIGHT);
|
||||
if (w > 0 && h > 0) {
|
||||
int maskTop = TEX_HEIGHT - h;
|
||||
int maskRight = TEX_WIDTH - w;
|
||||
|
||||
drawTextureWithMasking(matrix, x, y, sprite, maskTop, maskRight, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTextureWithMasking(Matrix4f matrix, int x, int y, TextureAtlasSprite sprite, int maskTop, int maskRight, int z) {
|
||||
float uMin = sprite.getU0();
|
||||
float uMax = sprite.getU1();
|
||||
float vMin = sprite.getV0();
|
||||
float vMax = sprite.getV1();
|
||||
uMax = uMax - (maskRight / 16F * (uMax - uMin));
|
||||
vMax = vMax - (maskTop / 16F * (vMax - vMin));
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuilder();
|
||||
bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
bufferBuilder.vertex(matrix, x, y + 16, z).uv(uMin, vMax).endVertex();
|
||||
bufferBuilder.vertex(matrix, x + 16 - maskRight, y + 16, z).uv(uMax, vMax).endVertex();
|
||||
bufferBuilder.vertex(matrix, x + 16 - maskRight, y + maskTop, z).uv(uMax, vMin).endVertex();
|
||||
bufferBuilder.vertex(matrix, x, y + maskTop, z).uv(uMin, vMin).endVertex();
|
||||
tessellator.end();
|
||||
}
|
||||
|
||||
private static void setGLColorFromInt(int color) {
|
||||
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
float alpha = ((color >> 24) & 0xFF) / 255F;
|
||||
|
||||
RenderSystem.color4f(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
private TextureAtlasSprite getStillFluidSprite(FluidStack stack) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
Fluid fluid = stack.getFluid();
|
||||
FluidAttributes attributes = fluid.getAttributes();
|
||||
ResourceLocation fluidStill = attributes.getStillTexture(stack);
|
||||
return minecraft.getTextureAtlas(PlayerContainer.BLOCK_ATLAS).apply(fluidStill);
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProcessUpdate process(List<IPortStorage> inputPorts, List<IPortStorage> outputPorts, ProcessUpdate update) {
|
||||
@@ -86,7 +85,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
|
||||
return update;
|
||||
}
|
||||
update.setTicksTaken(update.getTicksTaken() + 1);
|
||||
update.setMsg(update.getTicksTaken() / ticks + "%");
|
||||
update.setMsg((int)(((float)update.getTicksTaken() /(float)ticks) * 100) + "%");
|
||||
return update;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.ControllerBlock;
|
||||
import com.ticticboooom.mods.mm.block.MachinePortBlock;
|
||||
import com.ticticboooom.mods.mm.registration.MMLoader;
|
||||
import net.minecraft.block.DirectionalBlock;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
import net.minecraftforge.client.model.generators.ModelBuilder;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.client.model.generators.*;
|
||||
import net.minecraftforge.client.model.generators.loaders.MultiLayerModelBuilder;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
@@ -31,7 +30,13 @@ public class MMBlockStateProvider extends BlockStateProvider {
|
||||
protected void registerStatesAndModels() {
|
||||
for (RegistryObject<ControllerBlock> controller : MMLoader.BLOCKS) {
|
||||
dynamicBlockNorthOverlay(controller.getId(), BASE_TEXTURE, CONTROLLER_TEXTURE);
|
||||
simpleBlock(controller.get(), new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath())));
|
||||
VariantBlockStateBuilder variantBuilder = getVariantBuilder(controller.get());
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.NORTH).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(0).addModel();
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.SOUTH).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(180).addModel();
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.EAST).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(90).addModel();
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.WEST).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(270).addModel();
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.UP).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(0).addModel();
|
||||
variantBuilder.partialState().with(DirectionalBlock.FACING, Direction.DOWN).modelForState().modelFile(new ModelFile.UncheckedModelFile(new ResourceLocation(MM.ID, "block/" + controller.getId().getPath()))).rotationY(0).addModel();
|
||||
}
|
||||
|
||||
for (RegistryObject<MachinePortBlock> port : MMLoader.IPORT_BLOCKS) {
|
||||
@@ -45,7 +50,7 @@ public class MMBlockStateProvider extends BlockStateProvider {
|
||||
}
|
||||
|
||||
public void dynamicBlockNorthOverlay(ResourceLocation loc, ResourceLocation baseTexture, ResourceLocation overlayTexture) {
|
||||
models().getBuilder(loc.getPath()).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block")))
|
||||
models().getBuilder(loc.toString()).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block")))
|
||||
.texture("particle", overlayTexture)
|
||||
.transforms()
|
||||
.transform(ModelBuilder.Perspective.THIRDPERSON_LEFT)
|
||||
@@ -83,7 +88,7 @@ public class MMBlockStateProvider extends BlockStateProvider {
|
||||
.end();
|
||||
}
|
||||
public void dynamicBlock(ResourceLocation loc, ResourceLocation baseTexture, ResourceLocation overlayTexture) {
|
||||
models().getBuilder(loc.getPath()).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block")))
|
||||
models().getBuilder(loc.toString()).parent(new ModelFile.UncheckedModelFile(mcLoc("block/block")))
|
||||
.texture("particle", overlayTexture)
|
||||
.transforms()
|
||||
.transform(ModelBuilder.Perspective.THIRDPERSON_LEFT)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.ticticboooom.mods.mm.datagen.gen;
|
||||
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.ControllerBlock;
|
||||
import com.ticticboooom.mods.mm.block.MachinePortBlock;
|
||||
import com.ticticboooom.mods.mm.registration.MMLoader;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
public class MMItemModelProvider extends ItemModelProvider {
|
||||
|
||||
|
||||
public MMItemModelProvider(DataGenerator gen, ExistingFileHelper exFileHelper) {
|
||||
super(gen, MM.ID, exFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerModels() {
|
||||
for (RegistryObject<ControllerBlock> controller : MMLoader.BLOCKS) {
|
||||
this.getBuilder(controller.getId().toString()).parent(new ModelFile.UncheckedModelFile(new ResourceLocation(controller.getId().getNamespace(), "block/" + controller.getId().getPath())));
|
||||
}
|
||||
for (RegistryObject<MachinePortBlock> port : MMLoader.OPORT_BLOCKS) {
|
||||
this.getBuilder(port.getId().toString()).parent(new ModelFile.UncheckedModelFile(new ResourceLocation(port.getId().getNamespace(), "block/" + port.getId().getPath())));
|
||||
}
|
||||
for (RegistryObject<MachinePortBlock> port : MMLoader.IPORT_BLOCKS) {
|
||||
this.getBuilder(port.getId().toString()).parent(new ModelFile.UncheckedModelFile(new ResourceLocation(port.getId().getNamespace(), "block/" + port.getId().getPath())));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/ticticboooom/mods/mm/helper/InvHelper.java
Normal file
11
src/main/java/com/ticticboooom/mods/mm/helper/InvHelper.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.ticticboooom.mods.mm.helper;
|
||||
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class InvHelper {
|
||||
public static ItemStackInventory getItems(ItemStackHandler handler){
|
||||
return new ItemStackInventory(handler);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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 getContainerSize() {
|
||||
return handler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int p_70301_1_) {
|
||||
return handler.getStackInSlot(p_70301_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(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 removeItemNoUpdate(int p_70304_1_) {
|
||||
return handler.getStackInSlot(p_70304_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
handler.setStackInSlot(p_70299_1_, p_70299_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(PlayerEntity p_70300_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,18 @@ public class PortEnergyInventory implements IEnergyStorage {
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
if (simulate) {
|
||||
if (maxReceive + stored > capacity) {
|
||||
return (maxReceive + stored) - capacity;
|
||||
return maxReceive > capacity ? capacity - stored : maxReceive;
|
||||
} else {
|
||||
return 0;
|
||||
return maxReceive;
|
||||
}
|
||||
}
|
||||
if (maxReceive + stored > capacity) {
|
||||
int result = (maxReceive + stored) - capacity;
|
||||
int result = maxReceive > capacity ? capacity - stored : maxReceive;
|
||||
stored = capacity;
|
||||
return result;
|
||||
} else {
|
||||
stored += maxReceive;
|
||||
return 0;
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,4 +70,8 @@ public class PortEnergyInventory implements IEnergyStorage {
|
||||
public boolean canReceive() {
|
||||
return stored < capacity;
|
||||
}
|
||||
|
||||
public void setStored(int amount) {
|
||||
this.stored = amount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class PortFluidInventory implements IFluidHandler {
|
||||
|
||||
private FluidStack stack;
|
||||
private FluidStack stack = FluidStack.EMPTY;
|
||||
private final int capacity;
|
||||
public PortFluidInventory(int capacity) {
|
||||
this.capacity = capacity;
|
||||
@@ -36,31 +36,38 @@ public class PortFluidInventory implements IFluidHandler {
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
if (!resource.isFluidEqual(stack)) {
|
||||
if (!stack.isEmpty() && !resource.isFluidEqual(stack)) {
|
||||
return 0;
|
||||
}
|
||||
if (action == FluidAction.SIMULATE) {
|
||||
if (resource.getAmount() + stack.getAmount() > capacity) {
|
||||
return Math.abs(resource.getAmount() + stack.getAmount());
|
||||
return capacity - resource.getAmount();
|
||||
} else {
|
||||
return 0;
|
||||
return resource.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.getAmount() + stack.getAmount() > capacity) {
|
||||
int result = Math.abs(resource.getAmount() + stack.getAmount());
|
||||
stack.setAmount(capacity);
|
||||
return result;
|
||||
if (stack.isEmpty()) {
|
||||
stack = new FluidStack(resource.getFluid(), capacity);
|
||||
} else {
|
||||
stack.setAmount(capacity);
|
||||
}
|
||||
return capacity - resource.getAmount();
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() + resource.getAmount());
|
||||
return 0;
|
||||
if (stack.isEmpty()) {
|
||||
stack = new FluidStack(resource.getFluid(), resource.getAmount());
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() + resource.getAmount());
|
||||
}
|
||||
return resource.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
if (!resource.isFluidEqual(stack)) {
|
||||
if (!stack.isEmpty() && !resource.isFluidEqual(stack)) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
return innerDrain(resource.getAmount(), action == FluidAction.SIMULATE);
|
||||
@@ -89,4 +96,8 @@ public class PortFluidInventory implements IFluidHandler {
|
||||
return new FluidStack(stack.getFluid(), amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStack(FluidStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ticticboooom.mods.mm.network;
|
||||
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.network.packets.TileClientUpdatePacket;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
public class PacketHandler {
|
||||
private static final String PROTOCOL_VERSION = "1";
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation(MM.ID, "main"),
|
||||
() -> PROTOCOL_VERSION,
|
||||
PROTOCOL_VERSION::equals,
|
||||
PROTOCOL_VERSION::equals
|
||||
);
|
||||
|
||||
public static void init() {
|
||||
int index = 0;
|
||||
INSTANCE.registerMessage(index++, TileClientUpdatePacket.Data.class, TileClientUpdatePacket.Data::encode, TileClientUpdatePacket.Data::decode, TileClientUpdatePacket::handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.ticticboooom.mods.mm.network.packets;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TileClientUpdatePacket {
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static final class Data {
|
||||
private final BlockPos pos;
|
||||
private final CompoundNBT nbt;
|
||||
|
||||
public static void encode(Data data, PacketBuffer buffer){
|
||||
buffer.writeBlockPos(data.getPos());
|
||||
buffer.writeNbt(data.nbt);
|
||||
}
|
||||
|
||||
public static Data decode(PacketBuffer buffer){
|
||||
return new Data(buffer.readBlockPos(), buffer.readNbt());
|
||||
}
|
||||
}
|
||||
|
||||
public static void handle(Data data, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ClientWorld level = Minecraft.getInstance().level;
|
||||
TileEntity blockEntity = level.getBlockEntity(data.getPos());
|
||||
BlockState state = level.getBlockState(data.getPos());
|
||||
blockEntity.load(state, data.nbt);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public class FluidPortParser implements IPortParser {
|
||||
public void write(PacketBuffer buf, IPortState state) {
|
||||
buf.writeWithCodec(FluidPortState.CODEC, ((FluidPortState) state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPortState createState(JsonObject obj) {
|
||||
DataResult<Pair<FluidPortState, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(FluidPortState.CODEC).apply(obj);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -7,6 +8,7 @@ import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.ports.storage.IPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.ItemPortStorage;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -49,13 +51,13 @@ public class ItemPortState implements IPortState {
|
||||
if (!item.equals("")) {
|
||||
if (stackInSlot.getItem().getRegistryName().toString().equals(item)) {
|
||||
int amount = stackInSlot.getCount();
|
||||
stackInSlot.setCount(amount > current ? current : 0);
|
||||
stackInSlot.setCount(amount - (amount - current < 0 ? amount : current));
|
||||
current -= amount;
|
||||
}
|
||||
} else if (!tag.equals("")) {
|
||||
if (ItemTags.getAllTags().getTag(RLUtils.toRL(tag)).contains(stackInSlot.getItem())) {
|
||||
int amount = stackInSlot.getCount();
|
||||
stackInSlot.setCount(amount > current ? current : 0);
|
||||
stackInSlot.setCount(amount - (amount - current < 0 ? amount : current));
|
||||
current -= amount;
|
||||
|
||||
}
|
||||
@@ -106,9 +108,6 @@ public class ItemPortState implements IPortState {
|
||||
ItemPortStorage iinv = (ItemPortStorage) inv;
|
||||
for (int i = 0; i < iinv.getInv().getSlots(); i++) {
|
||||
ItemStack stackInSlot = iinv.getInv().getStackInSlot(i);
|
||||
if (stackInSlot.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!item.equals("")) {
|
||||
if (stackInSlot.getItem().getRegistryName().toString().equals(item)) {
|
||||
@@ -116,13 +115,10 @@ public class ItemPortState implements IPortState {
|
||||
int increment = Math.min((stackInSlot.getItem().getMaxStackSize() - amount), (count - current));
|
||||
stackInSlot.setCount(stackInSlot.getCount() + increment);
|
||||
current += increment;
|
||||
}
|
||||
} else if (!tag.equals("")) {
|
||||
if (ItemTags.getAllTags().getTag(RLUtils.toRL(tag)).contains(stackInSlot.getItem())) {
|
||||
int amount = stackInSlot.getCount();
|
||||
int increment = Math.min((stackInSlot.getItem().getMaxStackSize() - amount), (count - current));
|
||||
stackInSlot.setCount(stackInSlot.getCount() + increment);
|
||||
current += increment;
|
||||
} else if (stackInSlot.isEmpty()) {
|
||||
Item forgeItem = ForgeRegistries.ITEMS.getValue(RLUtils.toRL(item));
|
||||
iinv.getInv().setStackInSlot(i, new ItemStack(forgeItem, Math.min(forgeItem.getMaxStackSize(), count - current)));
|
||||
current += Math.min(forgeItem.getMaxStackSize(), count - current);
|
||||
}
|
||||
}
|
||||
if (current >= count) {
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
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.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.inventory.PortEnergyInventory;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
@@ -31,4 +41,36 @@ public class EnergyPortStorage implements IPortStorage {
|
||||
public <T> boolean validate(Capability<T> cap) {
|
||||
return cap == CapabilityEnergy.ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
nbt.putInt("stored", inv.getEnergyStored());
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
inv.setStored(nbt.getInt("stored"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
Minecraft.getInstance().textureManager.bind(new ResourceLocation(MM.ID, "textures/gui/port_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();
|
||||
}
|
||||
screen.blit(stack, left + barOffsetX, top + barOffsetY, 193, 18, 18, (int) (108 * amount));
|
||||
AbstractGui.drawString(stack, Minecraft.getInstance().font,Math.round((float)10000 * amount) / 100.f + "%", left + 30, top + 60, 0xfefefe);
|
||||
AbstractGui.drawString(stack, Minecraft.getInstance().font,inv.getEnergyStored() + "FE", left + 30, top + 80, 0xfefefe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
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.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.client.util.FluidRenderer;
|
||||
import com.ticticboooom.mods.mm.inventory.PortFluidInventory;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
|
||||
public class FluidPortStorage implements IPortStorage {
|
||||
@@ -32,4 +45,32 @@ public class FluidPortStorage implements IPortStorage {
|
||||
public <T> boolean validate(Capability<T> cap) {
|
||||
return cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
inv.getFluidInTank(0).writeToNBT(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
inv.setStack(FluidStack.loadFluidStackFromNBT(nbt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
Minecraft.getInstance().textureManager.bind(new ResourceLocation(MM.ID, "textures/gui/port_gui.png"));
|
||||
screen.blit(stack, left, top, 0, 0, 175, 256);
|
||||
int x = 78;
|
||||
int y = 40;
|
||||
screen.blit(stack, left + x, top + y, 175, 0, 18, 18);
|
||||
FluidRenderer.INSTANCE.render(stack, left + x + 1, top + y + 1, inv.getFluidInTank(0), 16);
|
||||
|
||||
AbstractGui.drawCenteredString(stack, Minecraft.getInstance().font, inv.getFluidInTank(0).getAmount() + " " + inv.getFluidInTank(0).getDisplayName().getString(), left + x + 9 + 1, top + y + 30, 0xfefefe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
package com.ticticboooom.mods.mm.ports.storage;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public interface IPortStorage {
|
||||
<T> LazyOptional<T> getLO();
|
||||
<T> boolean validate(Capability<T> cap);
|
||||
CompoundNBT save(CompoundNBT nbt);
|
||||
void load(CompoundNBT nbt);
|
||||
void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen);
|
||||
void setupContainer(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
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.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.helper.InvHelper;
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
import lombok.Getter;
|
||||
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.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
@@ -10,15 +22,23 @@ import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class ItemPortStorage implements IPortStorage {
|
||||
public static final Codec<ItemPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.INT.fieldOf("slots").forGetter(z -> z.inv.getSlots())
|
||||
Codec.INT.fieldOf("rows").forGetter(z -> z.rows),
|
||||
Codec.INT.fieldOf("columns").forGetter(z -> z.columns)
|
||||
).apply(x, ItemPortStorage::new));
|
||||
|
||||
@Getter
|
||||
private final ItemStackHandler inv;
|
||||
@Getter
|
||||
private final int rows;
|
||||
@Getter
|
||||
private final int columns;
|
||||
|
||||
private final LazyOptional<ItemStackHandler> invLO;
|
||||
|
||||
public ItemPortStorage(int slots) {
|
||||
this.inv = new ItemStackHandler(slots);
|
||||
public ItemPortStorage(int rows, int columns) {
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.inv = new ItemStackHandler(rows * columns);
|
||||
this.invLO = LazyOptional.of(() -> this.inv);
|
||||
}
|
||||
|
||||
@@ -32,4 +52,56 @@ public class ItemPortStorage implements IPortStorage {
|
||||
public <T> boolean validate(Capability<T> cap) {
|
||||
return cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
CompoundNBT compoundNBT = inv.serializeNBT();
|
||||
nbt = nbt.merge(compoundNBT);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
inv.deserializeNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
Minecraft.getInstance().textureManager.bind(new ResourceLocation(MM.ID, "textures/gui/port_gui.png"));
|
||||
screen.blit(stack, left, top, 0, 0, 175, 256);
|
||||
int offsetY = ((108 - (rows * 18)) / 2) + 7;
|
||||
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(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
int offsetX = ((162 - (columns * 18)) / 2) + 8;
|
||||
int offsetY = ((108 - (rows * 18)) / 2) + 8;
|
||||
ItemStackInventory items = InvHelper.getItems(this.inv);
|
||||
for (int y = 0; y < rows; y++) {
|
||||
for (int x = 0; x < columns; x++) {
|
||||
container.addSlot(new Slot(items, (y * rows) + x, x * 18 + offsetX, y * 18 + offsetY));
|
||||
}
|
||||
}
|
||||
int playerOffsetX = 8;
|
||||
int playerOffsetY = 141;
|
||||
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), 199));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class MMLoader {
|
||||
public static final ArrayList<RegistryObject<MachinePortBlock>> IPORT_BLOCKS = new ArrayList<>();
|
||||
public static final ArrayList<RegistryObject<MachinePortBlock>> OPORT_BLOCKS = new ArrayList<>();
|
||||
public static final ArrayList<RegistryObject<ContainerType<ControllerBlockContainer>>> CONTAINERS = new ArrayList<>();
|
||||
public static final ArrayList<RegistryObject<ContainerType<PortBlockContainer>>> PORT_CONTAINERS = new ArrayList<>();
|
||||
public static final ArrayList<RegistryObject<ContainerType<?>>> PORT_CONTAINERS = new ArrayList<RegistryObject<ContainerType<?>>>();
|
||||
|
||||
public static final DeferredRegister<Block> BLOCKS_REG = DeferredRegister.create(ForgeRegistries.BLOCKS, MM.ID);
|
||||
public static final DeferredRegister<Item> ITEMS_REG = DeferredRegister.create(ForgeRegistries.ITEMS, MM.ID);
|
||||
@@ -90,20 +90,24 @@ public class MMLoader {
|
||||
{
|
||||
Registerable<RegistryObject<TileEntityType<?>>> tile = new Registerable<>();
|
||||
Registerable<RegistryObject<MachinePortBlock>> block = new Registerable<>();
|
||||
Registerable<RegistryObject<ContainerType<?>>> cont = new Registerable<>();
|
||||
cont.set(CONTAINER_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_input", () -> IForgeContainerType.create((i, o, u) -> new PortBlockContainer(cont.get().get(), i, o, u))));
|
||||
block.set(BLOCKS_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_input", () -> new MachinePortBlock(tile.get())));
|
||||
tile.set(TILES_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_input", () -> TileEntityType.Builder.of(() -> new MachinePortBlockEntity(tile.get().get(), data.get(), true), block.get().get()).build(null)));
|
||||
tile.set(TILES_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_input", () -> TileEntityType.Builder.of(() -> new MachinePortBlockEntity(tile.get().get(),cont.get().get(), data.get(), true), block.get().get()).build(null)));
|
||||
ITEMS_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_input", () -> new BlockItem(block.get().get(), new Item.Properties().tab(MASTERFUL_ITEM_GROUP)));
|
||||
|
||||
PORT_CONTAINERS.add(cont.get());
|
||||
IPORT_BLOCKS.add(block.get());
|
||||
}
|
||||
|
||||
{
|
||||
Registerable<RegistryObject<TileEntityType<?>>> tile = new Registerable<>();
|
||||
Registerable<RegistryObject<MachinePortBlock>> block = new Registerable<>();
|
||||
Registerable<RegistryObject<ContainerType<?>>> cont = new Registerable<>();
|
||||
cont.set(CONTAINER_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_output", () -> IForgeContainerType.create((i, o, u) -> new PortBlockContainer(cont.get().get(), i, o, u))));
|
||||
block.set(BLOCKS_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_output", () -> new MachinePortBlock(tile.get())));
|
||||
tile.set(TILES_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_output", () -> TileEntityType.Builder.of(() -> new MachinePortBlockEntity(tile.get().get(), data.get(), false), block.get().get()).build(null)));
|
||||
tile.set(TILES_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_output", () -> TileEntityType.Builder.of(() -> new MachinePortBlockEntity(tile.get().get(), cont.get().get(), data.get(), false), block.get().get()).build(null)));
|
||||
ITEMS_REG.register(controllerId + "_port_" + resourceLocation.getPath() + "_output", () -> new BlockItem(block.get().get(), new Item.Properties().tab(MASTERFUL_ITEM_GROUP)));
|
||||
|
||||
PORT_CONTAINERS.add(cont.get());
|
||||
OPORT_BLOCKS.add(block.get());
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "masterfulmachinery:machine_process",
|
||||
"ticks": 20,
|
||||
"ticks": 600,
|
||||
"controllerId": "basic",
|
||||
"structureId": "test",
|
||||
"inputs": [
|
||||
|
||||
Reference in New Issue
Block a user