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")));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user