Some code changes I don't remember and port to 1.19.4
This commit is contained in:
@@ -6,27 +6,18 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Interface for BlockEntities that tick both Client and Server Side
|
||||
*/
|
||||
public interface ISidedTickable {
|
||||
|
||||
/**
|
||||
* Server Tick Event
|
||||
*
|
||||
* @param level
|
||||
* @param pos
|
||||
* @param state
|
||||
* @param blockEntity
|
||||
*/
|
||||
public void serverTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
|
||||
/**
|
||||
* Client Tick Event
|
||||
*
|
||||
* @param level
|
||||
* @param pos
|
||||
* @param state
|
||||
* @param blockEntity
|
||||
*/
|
||||
public void clientTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
|
||||
|
@@ -6,17 +6,13 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Interface for BlockEntities that only tick on a single side
|
||||
*/
|
||||
public interface ITickable {
|
||||
|
||||
/**
|
||||
* The Tick Event. Can be either Server or Client Sided
|
||||
*
|
||||
* @param level
|
||||
* @param pos
|
||||
* @param state
|
||||
* @param blockEntity
|
||||
*/
|
||||
public void tick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
|
||||
|
@@ -2,10 +2,9 @@ package me.hypherionmc.craterlib.api.blockentities.caps;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 24/09/2022
|
||||
* Wrapper Class for Forge Capabilities to remove duplicate code from Modules
|
||||
*/
|
||||
public enum ForgeCapability {
|
||||
public enum CapabilityHandler {
|
||||
ENERGY,
|
||||
ITEM,
|
||||
FLUID
|
@@ -0,0 +1,16 @@
|
||||
package me.hypherionmc.craterlib.api.blockentities.caps;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Interface for BlockEntities to expose "capabilities" across fabric/forge
|
||||
*/
|
||||
public interface ICraterCapProvider {
|
||||
|
||||
public <T> Optional<T> getCapability(CapabilityHandler handler, @Nullable Direction side);
|
||||
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package me.hypherionmc.craterlib.api.blockentities.caps;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 24/09/2022
|
||||
*/
|
||||
public interface IForgeCapProvider {
|
||||
|
||||
<T> Optional<T> getForgeCapability(ForgeCapability capability, Direction side);
|
||||
|
||||
}
|
@@ -8,16 +8,20 @@ import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Extention to allow mods to add their own creative tabs, without relying on loader events
|
||||
*/
|
||||
public class CraterCreativeModeTab implements Supplier<CreativeModeTab> {
|
||||
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final ItemStack icon;
|
||||
private final Supplier<ItemStack> icon;
|
||||
private final String backgroundSuffix;
|
||||
private CreativeModeTab tab;
|
||||
|
||||
protected CraterCreativeModeTab(Builder builder) {
|
||||
this.resourceLocation = builder.location;
|
||||
this.icon = builder.stack == null ? ItemStack.EMPTY : builder.stack;
|
||||
this.icon = builder.stack;
|
||||
this.backgroundSuffix = builder.backgroundSuffix == null ? "" : builder.backgroundSuffix;
|
||||
|
||||
CreativeTabRegistry.registerTab(this);
|
||||
@@ -27,7 +31,7 @@ public class CraterCreativeModeTab implements Supplier<CreativeModeTab> {
|
||||
return this.resourceLocation;
|
||||
}
|
||||
|
||||
public ItemStack getIcon() {
|
||||
public Supplier<ItemStack> getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -41,14 +45,14 @@ public class CraterCreativeModeTab implements Supplier<CreativeModeTab> {
|
||||
|
||||
public static class Builder {
|
||||
private final ResourceLocation location;
|
||||
private ItemStack stack;
|
||||
private Supplier<ItemStack> stack;
|
||||
private String backgroundSuffix;
|
||||
|
||||
public Builder(ResourceLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Builder setIcon(ItemStack icon) {
|
||||
public Builder setIcon(Supplier<ItemStack> icon) {
|
||||
stack = icon;
|
||||
return this;
|
||||
}
|
||||
|
@@ -3,14 +3,13 @@ package me.hypherionmc.craterlib.api.rendering;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Interface for defining Block render types
|
||||
*/
|
||||
public interface CustomRenderType {
|
||||
|
||||
/**
|
||||
* Get the render type of the block
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
RenderType getCustomRenderType();
|
||||
|
||||
|
@@ -4,21 +4,18 @@ import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Interface for Dyable Blocks
|
||||
*/
|
||||
public interface DyableBlock {
|
||||
|
||||
/**
|
||||
* Get the BlockColor handler for the block
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
BlockColor dyeHandler();
|
||||
|
||||
/**
|
||||
* Get the default Dye Color for Un-dyed states
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
DyeColor defaultDyeColor();
|
||||
|
||||
|
@@ -4,14 +4,13 @@ import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Interface for Dyable Items
|
||||
*/
|
||||
public interface ItemDyable {
|
||||
|
||||
/**
|
||||
* Get the DyeColor of the Item
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DyeColor getColor(ItemStack stack);
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import me.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||
import me.hypherionmc.craterlib.common.config.ModuleConfig;
|
||||
import me.hypherionmc.craterlib.common.config.annotations.SubConfig;
|
||||
import me.hypherionmc.craterlib.common.config.annotations.Tooltip;
|
||||
import me.hypherionmc.nightconfig.core.conversion.SpecComment;
|
||||
import me.hypherionmc.moonconfig.core.conversion.SpecComment;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
@@ -212,7 +212,7 @@ public class CraterConfigScreen extends Screen {
|
||||
int scrollbarPositionMinX = scrollbarPositionMaxX - 6;
|
||||
|
||||
int maxY = this.height - BOTTOM;
|
||||
RenderSystem.disableTexture();
|
||||
//RenderSystem.disableTexture();
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
@@ -233,7 +233,7 @@ public class CraterConfigScreen extends Screen {
|
||||
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
||||
tesselator.end();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
//RenderSystem.enableTexture();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class CraterConfigScreen extends Screen {
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(770, 771, 0, 1);
|
||||
RenderSystem.disableTexture();
|
||||
//RenderSystem.disableTexture();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
Matrix4f matrix = matrices.last().pose();
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
@@ -255,7 +255,7 @@ public class CraterConfigScreen extends Screen {
|
||||
buffer.vertex(matrix, width, height - BOTTOM - 4, 0.0F).uv(1, 0).color(0, 0, 0, 0).endVertex();
|
||||
buffer.vertex(matrix, 0, height - BOTTOM - 4, 0.0F).uv(0, 0).color(0, 0, 0, 0).endVertex();
|
||||
tesselator.end();
|
||||
RenderSystem.enableTexture();
|
||||
//RenderSystem.enableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InternalConfigButton extends AbstractButton {
|
||||
|
||||
@@ -19,7 +20,7 @@ public class InternalConfigButton extends AbstractButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, int i, int j, float f) {
|
||||
public void render(@NotNull PoseStack poseStack, int i, int j, float f) {
|
||||
if (cancel) {
|
||||
setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
} else {
|
||||
|
@@ -13,13 +13,13 @@ public class WrappedEditBox extends EditBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus(boolean bl) {
|
||||
public void setFocused(boolean bl) {
|
||||
for (GuiEventListener child : Minecraft.getInstance().screen.children()) {
|
||||
if (child instanceof TextConfigOption<?> option) {
|
||||
WrappedEditBox box = option.widget;
|
||||
box.setFocused(box == this);
|
||||
}
|
||||
}
|
||||
super.setFocus(bl);
|
||||
super.setFocused(bl);
|
||||
}
|
||||
}
|
||||
|
@@ -3,11 +3,15 @@ package me.hypherionmc.craterlib.client.registry;
|
||||
import me.hypherionmc.craterlib.api.rendering.DyableBlock;
|
||||
import me.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import me.hypherionmc.craterlib.client.rendering.ItemColorHandler;
|
||||
import me.hypherionmc.craterlib.platform.ClientPlatform;
|
||||
import me.hypherionmc.craterlib.systems.reg.RegistrationProvider;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
/**
|
||||
* Helper for registering Block and Item color handlers
|
||||
@@ -42,4 +46,8 @@ public class ClientRegistry {
|
||||
});
|
||||
}
|
||||
|
||||
public static void registerBlockEntityRenderer(BlockEntityType<? extends BlockEntity> blockEntityType, BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
ClientPlatform.CLIENT_HELPER.registerBlockEntityRenderer(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package me.hypherionmc.craterlib.common.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public abstract class ShapeShiftingBlock extends Block {
|
||||
|
||||
public ShapeShiftingBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
abstract protected VoxelShape getVoxelShape(BlockState state);
|
||||
|
||||
protected static VoxelShape mergeShapes(VoxelShape shape, VoxelShape shape2) {
|
||||
return Shapes.or(shape, shape2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockGetter levelReader, BlockPos blockPos, CollisionContext collisionContext) {
|
||||
return getVoxelShape(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter levelReader, BlockPos blockPos, CollisionContext collisionContext) {
|
||||
return getVoxelShape(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getInteractionShape(BlockState state, BlockGetter levelReader, BlockPos blockPos) {
|
||||
return getVoxelShape(state);
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package me.hypherionmc.craterlib.common.blockentity;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ForgeCapability;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.IForgeCapProvider;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ICraterCapProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -17,7 +18,7 @@ import java.util.Optional;
|
||||
* @date 24/09/2022
|
||||
* A Wrapped Block Entity to incorporate CraterLib's universal capability provider
|
||||
*/
|
||||
public class CraterBlockEntity extends BlockEntity implements IForgeCapProvider {
|
||||
public class CraterBlockEntity extends BlockEntity implements ICraterCapProvider {
|
||||
|
||||
public CraterBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state) {
|
||||
super(blockEntityType, pos, state);
|
||||
@@ -42,7 +43,7 @@ public class CraterBlockEntity extends BlockEntity implements IForgeCapProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getForgeCapability(ForgeCapability capability, Direction side) {
|
||||
public <T> Optional<T> getCapability(CapabilityHandler handler, @Nullable Direction side) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,54 @@
|
||||
package me.hypherionmc.craterlib.common.blockentity;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.platform.Platform;
|
||||
import me.hypherionmc.craterlib.systems.fluid.CraterFluidTank;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class FluidContainerBlockEntity extends CraterBlockEntity {
|
||||
|
||||
public final CraterFluidTank fluidTank;
|
||||
|
||||
public FluidContainerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, int capacity) {
|
||||
super(blockEntityType, pos, state);
|
||||
fluidTank = Platform.FLUID_HELPER.createFluidTank(capacity);
|
||||
}
|
||||
|
||||
public FluidContainerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, int capacity, Fluid... validFluids) {
|
||||
super(blockEntityType, pos, state);
|
||||
fluidTank = Platform.FLUID_HELPER.createFluidTank(capacity, validFluids);
|
||||
fluidTank.setChangeListener(this::sendUpdates);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
fluidTank.writeToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
fluidTank.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapability(CapabilityHandler handler, @Nullable Direction side) {
|
||||
if (handler == CapabilityHandler.FLUID) {
|
||||
return (Optional<T>) Optional.of(fluidTank);
|
||||
}
|
||||
return super.getCapability(handler, side);
|
||||
}
|
||||
|
||||
public CraterFluidTank getFluidTank() {
|
||||
return fluidTank;
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package me.hypherionmc.craterlib.common.config;
|
||||
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.nightconfig.core.file.FileWatcher;
|
||||
import me.hypherionmc.moonconfig.core.file.FileWatcher;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package me.hypherionmc.craterlib.common.config;
|
||||
|
||||
import me.hypherionmc.nightconfig.core.CommentedConfig;
|
||||
import me.hypherionmc.nightconfig.core.Config;
|
||||
import me.hypherionmc.nightconfig.core.conversion.ObjectConverter;
|
||||
import me.hypherionmc.nightconfig.core.file.CommentedFileConfig;
|
||||
import me.hypherionmc.moonconfig.core.CommentedConfig;
|
||||
import me.hypherionmc.moonconfig.core.Config;
|
||||
import me.hypherionmc.moonconfig.core.conversion.ObjectConverter;
|
||||
import me.hypherionmc.moonconfig.core.file.CommentedFileConfig;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package me.hypherionmc.craterlib.platform;
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.craterlib.platform.services.ILoaderHelper;
|
||||
import me.hypherionmc.craterlib.platform.services.LibCommonHelper;
|
||||
import me.hypherionmc.craterlib.platform.services.LibFluidHelper;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
@@ -12,6 +13,8 @@ public class Platform {
|
||||
|
||||
public static final LibCommonHelper COMMON_HELPER = load(LibCommonHelper.class);
|
||||
|
||||
public static final LibFluidHelper FLUID_HELPER = load(LibFluidHelper.class);
|
||||
|
||||
public static <T> T load(Class<T> clazz) {
|
||||
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
|
@@ -4,6 +4,7 @@ import me.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import me.hypherionmc.craterlib.network.CraterPacket;
|
||||
import me.hypherionmc.craterlib.systems.reg.RegistryObject;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -11,6 +12,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
@@ -38,4 +41,6 @@ public interface LibClientHelper {
|
||||
|
||||
public void registerClientReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory);
|
||||
|
||||
public void registerBlockEntityRenderer(BlockEntityType<? extends BlockEntity> blockEntityType, BlockEntityRendererProvider blockEntityRendererFactory);
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package me.hypherionmc.craterlib.platform.services;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.network.CraterNetworkHandler;
|
||||
import me.hypherionmc.craterlib.network.CraterPacket;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -10,14 +12,13 @@ import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -36,4 +37,5 @@ public interface LibCommonHelper {
|
||||
/* FABRIC ONLY */
|
||||
public void registerServerReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory);
|
||||
|
||||
public <T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CapabilityHandler capability);
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package me.hypherionmc.craterlib.platform.services;
|
||||
|
||||
import me.hypherionmc.craterlib.systems.fluid.CraterFluidTank;
|
||||
import me.hypherionmc.craterlib.systems.fluid.FluidHolder;
|
||||
import me.hypherionmc.craterlib.systems.fluid.ICraterFluidHandler;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface LibFluidHelper {
|
||||
|
||||
public CraterFluidTank createFluidTank(int capacity);
|
||||
|
||||
public CraterFluidTank createFluidTank(int capacity, Fluid... validFluids);
|
||||
|
||||
public boolean interactWithFluidHandler(Player player, InteractionHand hand, ICraterFluidHandler fluidHandler);
|
||||
|
||||
public boolean interactWithFluidHandler(@NotNull Player player, @NotNull InteractionHand hand, @NotNull Level level, @NotNull BlockPos pos, @Nullable Direction side);
|
||||
|
||||
public TextureAtlasSprite getFluidTexture(FluidHolder fluidHolder);
|
||||
|
||||
public int getFluidColor(Fluid fluid);
|
||||
|
||||
}
|
@@ -5,7 +5,7 @@ import net.minecraft.nbt.CompoundTag;
|
||||
/***
|
||||
* Loosely based on the Forge Energy System
|
||||
*/
|
||||
public class CustomEnergyStorage {
|
||||
public class CustomEnergyStorage implements ICraterEnergyStorage {
|
||||
|
||||
protected int powerLevel;
|
||||
protected int powerCapacity;
|
||||
@@ -31,11 +31,13 @@ public class CustomEnergyStorage {
|
||||
this.powerCapacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag writeNBT(CompoundTag compoundTag) {
|
||||
compoundTag.putInt("powerLevel", this.powerLevel);
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(CompoundTag compoundTag) {
|
||||
if (compoundTag.contains("powerLevel")) {
|
||||
this.powerLevel = compoundTag.getInt("powerLevel");
|
||||
@@ -49,6 +51,7 @@ public class CustomEnergyStorage {
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int toReceive, boolean test) {
|
||||
if (this.maxInput < 1) {
|
||||
return 0;
|
||||
@@ -63,6 +66,7 @@ public class CustomEnergyStorage {
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int toExtract, boolean test) {
|
||||
if (this.maxOutput < 1) {
|
||||
return 0;
|
||||
@@ -73,18 +77,22 @@ public class CustomEnergyStorage {
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerLevel() {
|
||||
return powerLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerCapacity() {
|
||||
return powerCapacity;
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package me.hypherionmc.craterlib.systems.energy;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface ICraterEnergyStorage {
|
||||
|
||||
public default CompoundTag writeNBT(CompoundTag tag) { return tag; }
|
||||
public default void readNBT(CompoundTag tag) {}
|
||||
|
||||
public int receiveEnergy(int toReceive, boolean test);
|
||||
public int extractEnergy(int toExtract, boolean test);
|
||||
|
||||
public int getPowerLevel();
|
||||
|
||||
public int getMaxInput();
|
||||
|
||||
public int getMaxOutput();
|
||||
|
||||
public int getPowerCapacity();
|
||||
|
||||
}
|
@@ -0,0 +1,149 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import me.hypherionmc.craterlib.util.FluidUtils;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CraterFluidTank implements ICraterFluidHandler {
|
||||
|
||||
private final int capacity;
|
||||
private final Predicate<FluidHolder> validFluid;
|
||||
private FluidHolder fluid = FluidHolder.EMPTY;
|
||||
|
||||
private ChangeListener contentsChanged;
|
||||
|
||||
public CraterFluidTank(int capacity) {
|
||||
this(capacity, e -> true);
|
||||
}
|
||||
|
||||
public CraterFluidTank(int capacity, Predicate<FluidHolder> validFluid) {
|
||||
this.capacity = capacity;
|
||||
this.validFluid = validFluid;
|
||||
}
|
||||
|
||||
public boolean isValidFluid(FluidHolder variant) {
|
||||
return validFluid.test(variant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(FluidHolder fluidHolder, FluidAction action) {
|
||||
if (fluidHolder.isEmpty() || !isValidFluid(fluidHolder)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (action.simulate()) {
|
||||
if (fluid.isEmpty()) {
|
||||
return Math.min(capacity, fluidHolder.getAmount());
|
||||
}
|
||||
if (!fluid.isFluidEqual(fluidHolder)) {
|
||||
return 0;
|
||||
}
|
||||
return Math.min(capacity - fluid.getAmount(), fluidHolder.getAmount());
|
||||
}
|
||||
|
||||
if (fluid.isEmpty()) {
|
||||
fluid = new FluidHolder(fluidHolder.getFluid(), Math.min(capacity, fluidHolder.getAmount()));
|
||||
return fluid.getAmount();
|
||||
}
|
||||
if (!fluid.isFluidEqual(fluidHolder)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int filled = capacity - fluid.getAmount();
|
||||
|
||||
if (fluidHolder.getAmount() < filled) {
|
||||
fluid.grow(fluidHolder.getAmount());
|
||||
filled = fluidHolder.getAmount();
|
||||
} else {
|
||||
fluid.setAmount(capacity);
|
||||
filled = capacity;
|
||||
}
|
||||
|
||||
if (filled > 0) {
|
||||
if (contentsChanged != null) {
|
||||
contentsChanged.onContentsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder extract(FluidHolder resource, FluidAction action) {
|
||||
if (resource.isEmpty() || !resource.isFluidEqual(fluid)) {
|
||||
return FluidHolder.EMPTY;
|
||||
}
|
||||
return extract(resource.getAmount(), action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder extract(int amount, FluidAction action) {
|
||||
int drained = amount;
|
||||
if (fluid.getAmount() < drained) {
|
||||
drained = fluid.getAmount();
|
||||
}
|
||||
|
||||
FluidHolder holder = new FluidHolder(fluid, drained);
|
||||
|
||||
if (action.execute() && drained > 0) {
|
||||
fluid.shrink(drained);
|
||||
}
|
||||
|
||||
if (contentsChanged != null) {
|
||||
contentsChanged.onContentsChanged();
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
|
||||
public void setContainedFluid(FluidHolder fluid) {
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTankEmpty() {
|
||||
return fluid.isEmpty();
|
||||
}
|
||||
|
||||
public int getSpace()
|
||||
{
|
||||
return Math.max(0, capacity - fluid.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder getFluidInTank() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankLevel() {
|
||||
return fluid.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag writeToNBT(CompoundTag tag) {
|
||||
FluidUtils.putFluid(tag, "fluid", fluid.getFluid());
|
||||
tag.putInt("tankLevel", fluid.getAmount());
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(CompoundTag tag) {
|
||||
fluid = new FluidHolder(FluidUtils.getFluidCompatible(tag), tag.getInt("tankLevel"));
|
||||
}
|
||||
|
||||
public void setChangeListener(ChangeListener contentsChanged) {
|
||||
this.contentsChanged = contentsChanged;
|
||||
}
|
||||
|
||||
public interface ChangeListener {
|
||||
void onContentsChanged();
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FluidHolder {
|
||||
|
||||
private Fluid fluid;
|
||||
private int amount;
|
||||
|
||||
public FluidHolder(FluidHolder holder) {
|
||||
this(holder.getFluid(), holder.getAmount());
|
||||
}
|
||||
|
||||
public FluidHolder(Fluid fluid, int amount) {
|
||||
this.fluid = fluid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public FluidHolder(FluidHolder fluid, int amount) {
|
||||
this.fluid = fluid.getFluid();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public static FluidHolder EMPTY = new FluidHolder(Fluids.EMPTY, 0);
|
||||
|
||||
public boolean isEmpty() {
|
||||
return amount == 0 || fluid.isSame(Fluids.EMPTY);
|
||||
}
|
||||
|
||||
public Fluid getFluid() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public boolean isFluidEqual(@NotNull FluidHolder other)
|
||||
{
|
||||
return this.getFluid() == other.getFluid();
|
||||
}
|
||||
|
||||
public void grow(int amount) {
|
||||
this.amount += amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void shrink(int amount) {
|
||||
this.amount -= amount;
|
||||
}
|
||||
|
||||
public FluidHolder copy() {
|
||||
return new FluidHolder(getFluid(), getAmount());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
|
||||
public interface ICraterFluidHandler {
|
||||
|
||||
enum FluidAction {
|
||||
EXECUTE,
|
||||
SIMULATE;
|
||||
|
||||
public boolean simulate() {
|
||||
return this == SIMULATE;
|
||||
}
|
||||
|
||||
public boolean execute() {
|
||||
return this == EXECUTE;
|
||||
}
|
||||
}
|
||||
|
||||
public int insert(FluidHolder fluidHolder, CraterFluidTank.FluidAction action);
|
||||
public FluidHolder extract(FluidHolder fluidHolder, CraterFluidTank.FluidAction action);
|
||||
public FluidHolder extract(int amount, CraterFluidTank.FluidAction action);
|
||||
public boolean isTankEmpty();
|
||||
public FluidHolder getFluidInTank();
|
||||
public int getTankLevel();
|
||||
public int getTankCapacity();
|
||||
|
||||
public default CompoundTag writeToNBT(CompoundTag tag) { return tag; }
|
||||
|
||||
public default void readFromNBT(CompoundTag tag) {};
|
||||
}
|
@@ -1,15 +1,24 @@
|
||||
package me.hypherionmc.craterlib.systems.internal;
|
||||
|
||||
import me.hypherionmc.craterlib.api.inventory.CraterCreativeModeTab;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class CreativeTabRegistry {
|
||||
|
||||
private static final List<CraterCreativeModeTab> TABS = new ArrayList<>();
|
||||
private static final List<Pair<CraterCreativeModeTab, Supplier<? extends ItemLike>>> TAB_ITEMS = new ArrayList<>();
|
||||
|
||||
public static void setCreativeTab(CraterCreativeModeTab tab, Supplier<? extends ItemLike> item) {
|
||||
TAB_ITEMS.add(Pair.of(tab, item));
|
||||
}
|
||||
|
||||
public static void registerTab(CraterCreativeModeTab tab) {
|
||||
TABS.add(tab);
|
||||
}
|
||||
@@ -18,4 +27,7 @@ public class CreativeTabRegistry {
|
||||
return TABS;
|
||||
}
|
||||
|
||||
public static List<Pair<CraterCreativeModeTab, Supplier<? extends ItemLike>>> getTabItems() {
|
||||
return TAB_ITEMS;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package me.hypherionmc.craterlib.systems;
|
||||
package me.hypherionmc.craterlib.systems.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.NonNullList;
|
@@ -0,0 +1,27 @@
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
|
||||
public class FluidUtils {
|
||||
|
||||
public static int fluidColorFromDye(DyeColor color) {
|
||||
return color.getMaterialColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static void putFluid(CompoundTag compound, String key, Fluid fluidVariant) {
|
||||
compound.putString("tankFluid", BuiltInRegistries.FLUID.getKey(fluidVariant).toString());
|
||||
}
|
||||
|
||||
public static Fluid getFluidCompatible(CompoundTag tag) {
|
||||
if (tag == null || !tag.contains("tankFluid"))
|
||||
return Fluids.EMPTY;
|
||||
|
||||
return BuiltInRegistries.FLUID.get(new ResourceLocation(tag.getString("tankFluid")));
|
||||
}
|
||||
|
||||
}
|
@@ -11,10 +11,11 @@ dependencies {
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
||||
include 'me.hypherionmc.night-config:toml:3.6.5_custom'
|
||||
include 'me.hypherionmc.night-config:core:3.6.5_custom'
|
||||
implementation project(":Common")
|
||||
|
||||
include "me.hypherionmc.moon-config:core:${moon_config}"
|
||||
include "me.hypherionmc.moon-config:toml:${moon_config}"
|
||||
|
||||
modApi("com.terraformersmc:modmenu:${mod_menu_version}") {
|
||||
exclude(group: "net.fabricmc.fabric-api")
|
||||
}
|
||||
|
@@ -1,13 +1,37 @@
|
||||
package me.hypherionmc.craterlib;
|
||||
|
||||
import me.hypherionmc.craterlib.common.FabricCommonHelper;
|
||||
import me.hypherionmc.craterlib.systems.internal.CreativeTabRegistry;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CraterLibInitializer implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> FabricCommonHelper.server = server);
|
||||
|
||||
CreativeTabRegistry.getTABS().forEach(tab -> {
|
||||
CreativeModeTab finalTab = FabricItemGroup.builder(tab.getResourceLocation())
|
||||
.title(Component.translatable("itemGroup." +
|
||||
tab.getResourceLocation().toString().replace(":", ".")
|
||||
))
|
||||
.displayItems((featureFlagSet, output) -> {
|
||||
CreativeTabRegistry
|
||||
.getTabItems()
|
||||
.stream().filter(t -> t.getLeft() == tab)
|
||||
.map(Pair::getRight).forEach(itm -> output.accept(itm.get()));
|
||||
})
|
||||
.icon(tab.getIcon())
|
||||
.build();
|
||||
|
||||
tab.setTab(finalTab);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -9,12 +9,14 @@ import me.hypherionmc.craterlib.util.ColorPropertyFunction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -23,6 +25,8 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
@@ -90,4 +94,9 @@ public class FabricClientHelper implements LibClientHelper {
|
||||
public static void registerCreativeItems(CreativeModeTab tab, FabricItemGroupEntries entries) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockEntityRenderer(BlockEntityType<? extends BlockEntity> blockEntityType, BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
BlockEntityRendererRegistry.register(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package me.hypherionmc.craterlib.client.gui.widgets;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import me.hypherionmc.craterlib.systems.fluid.FluidTank;
|
||||
import me.hypherionmc.craterlib.util.LangUtils;
|
||||
import me.hypherionmc.craterlib.util.RenderUtils;
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
@@ -15,9 +14,8 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -38,8 +36,7 @@ public class FluidStackWidget extends AbstractWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
public void renderWidget(@NotNull PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
@@ -71,7 +68,8 @@ public class FluidStackWidget extends AbstractWidget {
|
||||
for (int i = 0; i < Math.ceil(renderableHeight / 16f); i++) {
|
||||
int drawingHeight = Math.min(16, renderableHeight - 16 * i);
|
||||
int notDrawingHeight = 16 - drawingHeight;
|
||||
blit(matrices, getX(), getY() + notDrawingHeight, displayOn.getBlitOffset(), still.getU0() * atlasWidth, still.getV0() * atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
// TODO Double Check this
|
||||
blit(matrices, getX(), getY() + notDrawingHeight, 0, still.getU0() * atlasWidth, still.getV0() * atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
matrices.translate(0, -16, 0);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package me.hypherionmc.craterlib.common;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ICraterCapProvider;
|
||||
import me.hypherionmc.craterlib.network.CraterNetworkHandler;
|
||||
import me.hypherionmc.craterlib.network.CraterPacket;
|
||||
import me.hypherionmc.craterlib.network.FabricNetworkHandler;
|
||||
@@ -8,6 +10,7 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -19,9 +22,11 @@ import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -79,4 +84,11 @@ public class FabricCommonHelper implements LibCommonHelper {
|
||||
return new ExtendedScreenHandlerType<>(constructor::apply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CapabilityHandler capability) {
|
||||
if (entity instanceof ICraterCapProvider capProvider) {
|
||||
return capProvider.getCapability(capability, side);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package me.hypherionmc.craterlib.common;
|
||||
|
||||
import me.hypherionmc.craterlib.platform.services.LibFluidHelper;
|
||||
import me.hypherionmc.craterlib.systems.fluid.*;
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
import net.fabricmc.fabric.impl.transfer.fluid.FluidVariantImpl;
|
||||
import net.fabricmc.fabric.mixin.transfer.BucketItemAccessor;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BucketItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricFluidHelper implements LibFluidHelper {
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity) {
|
||||
return new FluidTank(capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity, Fluid... validFluids) {
|
||||
return new FluidTank(capacity, (variant) -> Arrays.stream(validFluids).allMatch(f -> f.isSame(variant.getFluid())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(Player player, InteractionHand hand, ICraterFluidHandler fluidHandler) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() instanceof BucketItem bucketItem) {
|
||||
FluidVariant fluidVariant = new FluidVariantImpl(((BucketItemAccessor) bucketItem).fabric_getFluid(), stack.getTag());
|
||||
if (fluidVariant.isBlank())
|
||||
return false;
|
||||
if (fluidHandler.insert(new FluidHolder(fluidVariant.getFluid(), 1000), ICraterFluidHandler.FluidAction.EXECUTE) > 0) {
|
||||
player.level.playSound(null, player.getOnPos(), SoundEvents.BUCKET_EMPTY, SoundSource.BLOCKS, 1.0f, 1.0f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(@NotNull Player player, @NotNull InteractionHand hand, @NotNull Level level, @NotNull BlockPos pos, @Nullable Direction side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getFluidTexture(FluidHolder fluidHolder) {
|
||||
return FabricFluidUtils.getFluidTexture(FluidVariant.of(fluidHolder.getFluid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidColor(Fluid fluid) {
|
||||
return FluidVariantRendering.getColor(FluidVariant.of(fluid));
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
public class FabricFluidUtils {
|
||||
|
||||
public static TextureAtlasSprite getFluidTexture(FluidVariant fluidStack) {
|
||||
return FluidVariantRendering.getSprite(fluidStack);
|
||||
}
|
||||
|
||||
}
|
@@ -5,59 +5,35 @@ import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
|
||||
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions;
|
||||
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
|
||||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class FluidTank implements Storage<FluidVariant>, StorageView<FluidVariant> {
|
||||
|
||||
private final long capacity;
|
||||
private final Predicate<FluidVariant> validFluid;
|
||||
private long level = 0;
|
||||
private FluidVariant fluid = FluidVariant.blank();
|
||||
public class FluidTank extends CraterFluidTank implements Storage<FluidVariant>, StorageView<FluidVariant> {
|
||||
|
||||
public FluidTank(long capacity) {
|
||||
this(capacity, e -> true);
|
||||
}
|
||||
|
||||
public FluidTank(long capacity, Predicate<FluidVariant> validFluid) {
|
||||
this.capacity = capacity;
|
||||
this.validFluid = validFluid;
|
||||
super((int) capacity, (p) -> validFluid.test(FluidVariant.of(p.getFluid())));
|
||||
}
|
||||
|
||||
public boolean isFluidValid(FluidVariant variant) {
|
||||
return validFluid.test(variant);
|
||||
return isValidFluid(new FluidHolder(variant.getFluid(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) {
|
||||
StoragePreconditions.notBlankNotNegative(resource, maxAmount);
|
||||
if (this.fluid.isBlank() || this.fluid.equals(resource)) {
|
||||
long inserted = Math.min(maxAmount, capacity - level);
|
||||
if (inserted > 0) {
|
||||
level += inserted;
|
||||
this.fluid = resource;
|
||||
}
|
||||
return inserted;
|
||||
}
|
||||
return 0;
|
||||
return insert(new FluidHolder(resource.getFluid(), (int) maxAmount), FluidAction.EXECUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) {
|
||||
StoragePreconditions.notBlankNotNegative(resource, maxAmount);
|
||||
if (resource.equals(fluid)) {
|
||||
long extracted = Math.min(maxAmount, level);
|
||||
if (extracted > 0) {
|
||||
level -= extracted;
|
||||
if (level == 0) {
|
||||
this.fluid = FluidVariant.blank();
|
||||
}
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
return 0;
|
||||
FluidHolder extracted = extract(new FluidHolder(resource.getFluid(), (int) maxAmount), FluidAction.EXECUTE);
|
||||
return extracted.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,32 +44,21 @@ public class FluidTank implements Storage<FluidVariant>, StorageView<FluidVarian
|
||||
|
||||
@Override
|
||||
public boolean isResourceBlank() {
|
||||
return fluid.isBlank();
|
||||
return isTankEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidVariant getResource() {
|
||||
return fluid;
|
||||
return FluidVariant.of(getFluidInTank().getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAmount() {
|
||||
return level;
|
||||
return getTankLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public CompoundTag writeNbt(CompoundTag compound) {
|
||||
FluidUtils.putFluid(compound, "fluid", getResource());
|
||||
compound.putLong("amt", level);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readNbt(CompoundTag nbtCompound) {
|
||||
fluid = FluidUtils.getFluidCompatible(nbtCompound, "fluid");
|
||||
level = nbtCompound.getLong("amt");
|
||||
return getTankCapacity();
|
||||
}
|
||||
}
|
||||
|
@@ -1,55 +0,0 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
|
||||
public class FluidUtils {
|
||||
|
||||
public static int fluidColorFromDye(DyeColor color) {
|
||||
return color.getMaterialColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static void putFluid(CompoundTag compound, String key, FluidVariant fluidVariant) {
|
||||
CompoundTag savedTag = new CompoundTag();
|
||||
savedTag.put("fk", fluidVariant.toNbt());
|
||||
compound.put(key, savedTag);
|
||||
}
|
||||
|
||||
public static FluidVariant getFluidCompatible(CompoundTag tag, String key) {
|
||||
if (tag == null || !tag.contains(key))
|
||||
return FluidVariant.blank();
|
||||
|
||||
if (tag.get(key) instanceof StringTag) {
|
||||
return FluidVariant.of(BuiltInRegistries.FLUID.get(new ResourceLocation(tag.getString(key))));
|
||||
} else {
|
||||
CompoundTag compound = tag.getCompound(key);
|
||||
if (compound.contains("fk")) {
|
||||
return FluidVariant.fromNbt(compound.getCompound("fk"));
|
||||
} else {
|
||||
return FluidVariant.of(readLbaTag(tag.getCompound(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Fluid readLbaTag(CompoundTag tag) {
|
||||
if (tag.contains("ObjName") && tag.getString("Registry").equals("f")) {
|
||||
return BuiltInRegistries.FLUID.get(new ResourceLocation(tag.getString("ObjName")));
|
||||
} else {
|
||||
return Fluids.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public static TextureAtlasSprite getFluidTexture(FluidVariant fluidStack) {
|
||||
return FluidVariantRendering.getSprite(fluidStack);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1 @@
|
||||
me.hypherionmc.craterlib.common.FabricFluidHelper
|
@@ -16,9 +16,6 @@
|
||||
"icon": "assets/modid/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"preLaunch": [
|
||||
"me.hypherionmc.craterlib.CraterLibInitializer"
|
||||
],
|
||||
"main": [
|
||||
"me.hypherionmc.craterlib.CraterLibInitializer"
|
||||
],
|
||||
|
@@ -102,8 +102,8 @@ processResources {
|
||||
|
||||
shadowJar {
|
||||
dependencies {
|
||||
include(dependency('me.hypherionmc.night-config:toml:3.6.5_custom'))
|
||||
include(dependency('me.hypherionmc.night-config:core:3.6.5_custom'))
|
||||
include(dependency("me.hypherionmc.moon-config:core:${moon_config}"))
|
||||
include(dependency("me.hypherionmc.moon-config:toml:${moon_config}"))
|
||||
|
||||
//relocate 'me.hypherionmc.nightconfig', 'shadow.hypherionmc.nightconfig'
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@ import me.hypherionmc.craterlib.systems.reg.RegistryObject;
|
||||
import me.hypherionmc.craterlib.util.ColorPropertyFunction;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.item.ItemProperties;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
@@ -16,6 +18,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -71,4 +75,9 @@ public class ForgeClientHelper implements LibClientHelper {
|
||||
public void registerClientReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory) {
|
||||
// UNUSED
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockEntityRenderer(BlockEntityType<? extends BlockEntity> blockEntityType, BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
BlockEntityRenderers.register(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ package me.hypherionmc.craterlib.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import me.hypherionmc.craterlib.util.LangUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
@@ -22,8 +21,8 @@ import net.minecraft.util.FastColor;
|
||||
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** Copied from https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.18.x/enderio-machines/src/main/java/com/enderio/machines/client/FluidStackWidget.java*/
|
||||
@@ -42,7 +41,7 @@ public class FluidStackWidget extends AbstractWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTicks) {
|
||||
public void renderWidget(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTicks) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
@@ -79,7 +78,8 @@ public class FluidStackWidget extends AbstractWidget {
|
||||
for (int i = 0; i < Math.ceil(renderableHeight / 16f); i++) {
|
||||
int drawingHeight = Math.min(16, renderableHeight - 16*i);
|
||||
int notDrawingHeight = 16 - drawingHeight;
|
||||
blit(pPoseStack, getX(), getY() + notDrawingHeight, displayOn.getBlitOffset(), sprite.getU0()*atlasWidth, sprite.getV0()*atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
// TODO Double Check this
|
||||
blit(pPoseStack, getX(), getY() + notDrawingHeight, 0, sprite.getU0()*atlasWidth, sprite.getV0()*atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
pPoseStack.translate(0,-16, 0);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package me.hypherionmc.craterlib.common;
|
||||
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.craterlib.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraftforge.event.CreativeModeTabEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -11,11 +12,18 @@ import net.minecraftforge.fml.common.Mod;
|
||||
public class ForgeCommonEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void buildContents(CreativeModeTabEvent.Register event) {
|
||||
public static void registerTabs(CreativeModeTabEvent.Register event) {
|
||||
CraterConstants.LOG.info("Registering Creative Tabs");
|
||||
|
||||
CreativeTabRegistry.getTABS().forEach(tab -> {
|
||||
CreativeModeTab creativeModeTab = event.registerCreativeModeTab(tab.getResourceLocation(), builder -> {
|
||||
builder.icon(tab::getIcon);
|
||||
builder.title(
|
||||
Component.translatable("itemGroup." +
|
||||
tab.getResourceLocation().toString().replace(":", ".")
|
||||
)
|
||||
);
|
||||
|
||||
builder.icon(tab.getIcon());
|
||||
|
||||
if (!tab.getBackgroundSuffix().isEmpty()) {
|
||||
builder.backgroundSuffix(tab.getBackgroundSuffix());
|
||||
@@ -25,4 +33,13 @@ public class ForgeCommonEvents {
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTabs(CreativeModeTabEvent.BuildContents event) {
|
||||
CreativeModeTab tab = event.getTab();
|
||||
|
||||
CreativeTabRegistry.getTabItems().stream()
|
||||
.filter(p -> p.getLeft().get() == tab)
|
||||
.forEach(itemPair -> event.accept(itemPair.getRight()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,15 @@
|
||||
package me.hypherionmc.craterlib.common;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ICraterCapProvider;
|
||||
import me.hypherionmc.craterlib.network.CraterNetworkHandler;
|
||||
import me.hypherionmc.craterlib.network.CraterPacket;
|
||||
import me.hypherionmc.craterlib.network.ForgeNetworkHandler;
|
||||
import me.hypherionmc.craterlib.platform.services.LibCommonHelper;
|
||||
import me.hypherionmc.craterlib.systems.energy.ForgeEnergyReader;
|
||||
import me.hypherionmc.craterlib.systems.fluid.ForgeFluidReader;
|
||||
import me.hypherionmc.craterlib.systems.fluid.ICraterFluidHandler;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -13,7 +19,8 @@ import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
@@ -22,9 +29,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -64,4 +72,27 @@ public class ForgeCommonHelper implements LibCommonHelper {
|
||||
public <T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<Integer, Inventory, FriendlyByteBuf, T> constructor) {
|
||||
return IForgeMenuType.create(constructor::apply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CapabilityHandler capability) {
|
||||
if (capability == CapabilityHandler.ENERGY) {
|
||||
AtomicReference<ForgeEnergyReader> energyReference = new AtomicReference<>();
|
||||
entity.getCapability(ForgeCapabilities.ENERGY, side).ifPresent(storage -> energyReference.set(new ForgeEnergyReader(storage)));
|
||||
|
||||
return energyReference.get() != null ? (Optional<T>) Optional.of(energyReference.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
if (capability == CapabilityHandler.FLUID) {
|
||||
AtomicReference<ICraterFluidHandler> craterFluidHandler = new AtomicReference<>();
|
||||
entity.getCapability(ForgeCapabilities.FLUID_HANDLER, side).ifPresent(iFluidHandler -> craterFluidHandler.set(new ForgeFluidReader(iFluidHandler)));
|
||||
|
||||
return craterFluidHandler.get() != null ? (Optional<T>) Optional.of(craterFluidHandler.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
if (entity instanceof ICraterCapProvider capProvider) {
|
||||
return capProvider.getCapability(capability, side);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,53 @@
|
||||
package me.hypherionmc.craterlib.common;
|
||||
|
||||
import me.hypherionmc.craterlib.platform.services.LibFluidHelper;
|
||||
import me.hypherionmc.craterlib.systems.fluid.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ForgeFluidHelper implements LibFluidHelper {
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity) {
|
||||
return new ForgeWrappedFluidTank(capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity, Fluid... validFluids) {
|
||||
return new ForgeWrappedFluidTank(capacity, (variant) -> Arrays.stream(validFluids).allMatch(f -> f.isSame(variant.getFluid())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(Player player, InteractionHand hand, ICraterFluidHandler fluidHandler) {
|
||||
ForgeFluidTankInteractor interactor = new ForgeFluidTankInteractor(fluidHandler);
|
||||
return FluidUtil.interactWithFluidHandler(player, hand, interactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(@NotNull Player player, @NotNull InteractionHand hand, @NotNull Level level, @NotNull BlockPos pos, @Nullable Direction side) {
|
||||
return FluidUtil.interactWithFluidHandler(player, hand, level, pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getFluidTexture(FluidHolder fluidHolder) {
|
||||
return ForgeFluidUtils.getFluidTexture(new FluidStack(fluidHolder.getFluid(), 0), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidColor(Fluid fluid) {
|
||||
IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluid);
|
||||
return props.getTintColor();
|
||||
}
|
||||
}
|
@@ -1,12 +1,15 @@
|
||||
package me.hypherionmc.craterlib.mixin;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ForgeCapability;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.IForgeCapProvider;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.CapabilityHandler;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ICraterCapProvider;
|
||||
import me.hypherionmc.craterlib.common.blockentity.CraterBlockEntity;
|
||||
import me.hypherionmc.craterlib.systems.SimpleInventory;
|
||||
import me.hypherionmc.craterlib.systems.energy.CustomEnergyStorage;
|
||||
import me.hypherionmc.craterlib.systems.energy.ForgeEnergyWrapper;
|
||||
import me.hypherionmc.craterlib.systems.fluid.CraterFluidTank;
|
||||
import me.hypherionmc.craterlib.systems.fluid.ForgeWrappedFluidTank;
|
||||
import me.hypherionmc.craterlib.systems.fluid.ICraterFluidHandler;
|
||||
import me.hypherionmc.craterlib.systems.inventory.ForgeInventoryWrapper;
|
||||
import me.hypherionmc.craterlib.systems.inventory.SimpleInventory;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
@@ -28,22 +31,29 @@ public class BlockEntityMixin implements ICapabilityProvider {
|
||||
|
||||
@Override
|
||||
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||
IForgeCapProvider capProvider = (IForgeCapProvider) this;
|
||||
ICraterCapProvider capProvider = (ICraterCapProvider) this;
|
||||
|
||||
if (cap == ForgeCapabilities.ENERGY) {
|
||||
Optional<CustomEnergyStorage> forgeCap = capProvider.getForgeCapability(ForgeCapability.ENERGY, side);
|
||||
Optional<CustomEnergyStorage> forgeCap = capProvider.getCapability(CapabilityHandler.ENERGY, side);
|
||||
if (forgeCap.isPresent()) {
|
||||
return LazyOptional.of(() -> new ForgeEnergyWrapper(forgeCap.get())).cast();
|
||||
}
|
||||
}
|
||||
|
||||
if (cap == ForgeCapabilities.ITEM_HANDLER) {
|
||||
Optional<SimpleInventory> inventory = capProvider.getForgeCapability(ForgeCapability.ITEM, side);
|
||||
Optional<SimpleInventory> inventory = capProvider.getCapability(CapabilityHandler.ITEM, side);
|
||||
if (inventory.isPresent()) {
|
||||
return LazyOptional.of(() -> new SidedInvWrapper(new ForgeInventoryWrapper(inventory.get()), side)).cast();
|
||||
}
|
||||
}
|
||||
|
||||
if (cap == ForgeCapabilities.FLUID_HANDLER) {
|
||||
Optional<ICraterFluidHandler> fluidTank = capProvider.getCapability(CapabilityHandler.FLUID, side);
|
||||
if (fluidTank.isPresent()) {
|
||||
return LazyOptional.of(() -> (ForgeWrappedFluidTank)fluidTank.get()).cast();
|
||||
}
|
||||
}
|
||||
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package me.hypherionmc.craterlib.systems.energy;
|
||||
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
public record ForgeEnergyReader(IEnergyStorage forgeStorage) implements ICraterEnergyStorage {
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int toReceive, boolean test) {
|
||||
return forgeStorage.receiveEnergy(toReceive, test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int toExtract, boolean test) {
|
||||
return forgeStorage.extractEnergy(toExtract, test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerLevel() {
|
||||
return forgeStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerCapacity() {
|
||||
return forgeStorage().getMaxEnergyStored();
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public record ForgeFluidReader(IFluidHandler fluidHandler) implements ICraterFluidHandler {
|
||||
|
||||
@Override
|
||||
public int insert(FluidHolder fluidHolder, FluidAction action) {
|
||||
return fluidHandler.fill(new FluidStack(fluidHolder.getFluid(), fluidHolder.getAmount()), action.simulate() ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder extract(FluidHolder fluidHolder, FluidAction action) {
|
||||
FluidStack extracted = fluidHandler.drain(new FluidStack(fluidHolder.getFluid(), fluidHolder.getAmount()), action.simulate() ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
|
||||
return new FluidHolder(extracted.getFluid(), extracted.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder extract(int amount, FluidAction action) {
|
||||
FluidStack extracted = fluidHandler.drain(amount, action.simulate() ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
|
||||
return new FluidHolder(extracted.getFluid(), extracted.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTankEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidHolder getFluidInTank() {
|
||||
return FluidHolder.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity() {
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ForgeFluidTankInteractor(ICraterFluidHandler fluidHandler) implements IFluidHandler {
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack getFluidInTank(int tank) {
|
||||
return new FluidStack(fluidHandler.getFluidInTank().getFluid(), fluidHandler.getFluidInTank().getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return fluidHandler.getTankCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(int tank, @NotNull FluidStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
return fluidHandler.insert(new FluidHolder(resource.getFluid(), resource.getAmount()), action.simulate() ? ICraterFluidHandler.FluidAction.SIMULATE : ICraterFluidHandler.FluidAction.EXECUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
FluidHolder drained = fluidHandler.extract(new FluidHolder(resource.getFluid(), resource.getAmount()), action.simulate() ? ICraterFluidHandler.FluidAction.SIMULATE : ICraterFluidHandler.FluidAction.EXECUTE);
|
||||
return new FluidStack(drained.getFluid(), drained.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack drain(int maxDrain, FluidAction action) {
|
||||
FluidHolder drained = fluidHandler.extract(maxDrain, action.simulate() ? ICraterFluidHandler.FluidAction.SIMULATE : ICraterFluidHandler.FluidAction.EXECUTE);
|
||||
return new FluidStack(drained.getFluid(), drained.getAmount());
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class ForgeFluidUtils {
|
||||
|
||||
public static TextureAtlasSprite getFluidTexture(FluidStack fluidStack, boolean still) {
|
||||
IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluidStack.getFluid());
|
||||
ResourceLocation fluidStill = still ? props.getStillTexture(fluidStack) : props.getFlowingTexture(fluidStack);
|
||||
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS);
|
||||
|
||||
if (texture instanceof TextureAtlas atlas) {
|
||||
return atlas.getSprite(fluidStill);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package me.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ForgeWrappedFluidTank extends CraterFluidTank implements IFluidTank, IFluidHandler {
|
||||
|
||||
public ForgeWrappedFluidTank(int capacity) {
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
public ForgeWrappedFluidTank(int capacity, Predicate<FluidStack> predicate) {
|
||||
super(capacity, p -> predicate.test(new FluidStack(p.getFluid(), p.getAmount())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack getFluid() {
|
||||
return new FluidStack(this.getFluidInTank().getFluid(), this.getTankLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount() {
|
||||
return this.getTankLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return this.getTankCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(FluidStack stack) {
|
||||
return this.isValidFluid(new FluidHolder(stack.getFluid(), stack.getAmount()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack getFluidInTank(int tankInt) {
|
||||
return new FluidStack(this.getFluidInTank().getFluid(), this.getTankLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tankInt) {
|
||||
return this.getTankCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(int tankInt, @NotNull FluidStack stack) {
|
||||
return this.isValidFluid(new FluidHolder(stack.getFluid(), stack.getAmount()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, IFluidHandler.FluidAction action) {
|
||||
return this.insert(new FluidHolder(resource.getFluid(), resource.getAmount()), action.simulate() ? CraterFluidTank.FluidAction.SIMULATE : CraterFluidTank.FluidAction.EXECUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) {
|
||||
FluidHolder extracted = this.extract(maxDrain, action.simulate() ? CraterFluidTank.FluidAction.SIMULATE : CraterFluidTank.FluidAction.EXECUTE);
|
||||
return new FluidStack(extracted.getFluid(), extracted.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action) {
|
||||
FluidHolder holder = this.extract(new FluidHolder(resource.getFluid(), resource.getAmount()), action.simulate() ? CraterFluidTank.FluidAction.SIMULATE : CraterFluidTank.FluidAction.EXECUTE);
|
||||
return new FluidStack(holder.getFluid(), holder.getAmount());
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
package me.hypherionmc.craterlib.systems.inventory;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import me.hypherionmc.craterlib.systems.SimpleInventory;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@@ -0,0 +1 @@
|
||||
me.hypherionmc.craterlib.common.ForgeFluidHelper
|
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.matyrobbrt.mc.registrationutils' version '1.19.3-1.0.0'
|
||||
id 'com.matyrobbrt.mc.registrationutils' version '1.19.3-2.0.1'
|
||||
}
|
||||
|
||||
registrationUtils {
|
||||
@@ -44,7 +44,7 @@ subprojects {
|
||||
'Implementation-Version' : project.jar.archiveVersion,
|
||||
'Implementation-Vendor' : mod_author,
|
||||
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
'Timestampe' : System.currentTimeMillis(),
|
||||
'Timestamp' : System.currentTimeMillis(),
|
||||
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
|
||||
'Build-On-Minecraft' : minecraft_version
|
||||
])
|
||||
@@ -68,8 +68,8 @@ subprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'me.hypherionmc.night-config:toml:3.6.5_custom'
|
||||
implementation 'me.hypherionmc.night-config:core:3.6.5_custom'
|
||||
implementation "me.hypherionmc.moon-config:core:${moon_config}"
|
||||
implementation "me.hypherionmc.moon-config:toml:${moon_config}"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
|
@@ -1,21 +1,21 @@
|
||||
# Project
|
||||
version_major=0
|
||||
version_minor=0
|
||||
version_patch=6d
|
||||
version_patch=1d
|
||||
group=me.hypherionmc.craterlib
|
||||
|
||||
# Common
|
||||
minecraft_version=1.19.3
|
||||
minecraft_version=1.19.4
|
||||
common_runs_enabled=false
|
||||
common_client_run_name=Common Client
|
||||
common_server_run_name=Common Server
|
||||
|
||||
# Forge
|
||||
forge_version=44.0.41
|
||||
forge_version=45.0.9
|
||||
forge_ats_enabled=true
|
||||
|
||||
# Fabric
|
||||
fabric_version=0.70.0+1.19.3
|
||||
fabric_version=0.76.0+1.19.4
|
||||
fabric_loader_version=0.14.9
|
||||
|
||||
# Mod options
|
||||
@@ -28,4 +28,5 @@ org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
# Dependencies
|
||||
mod_menu_version=5.0.2
|
||||
mod_menu_version=6.1.0-rc.4
|
||||
moon_config=1.0.9
|
||||
|
Reference in New Issue
Block a user