[CHORE] Cleanup API's that's unused by any mod currently
This commit is contained in:
@@ -24,7 +24,6 @@ shadowJar {
|
||||
unimined.minecraft {
|
||||
fabric {
|
||||
loader fabric_loader
|
||||
accessWidener(project.file("src/main/resources/${mod_id}.aw"))
|
||||
}
|
||||
|
||||
defaultRemapJar = false
|
||||
|
@@ -1,2 +1,2 @@
|
||||
# We don't need the common jar to be remapped
|
||||
fabric.loom.dontRemap = true
|
||||
fabric.loom.dontRemap=true
|
@@ -1,17 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.blockentity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
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 {
|
||||
|
||||
void serverTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
void clientTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.blockentity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
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 {
|
||||
|
||||
void tick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity);
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.blockentity.caps;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Wrapper class for Forge capabilities to remove duplicate code from modules
|
||||
*/
|
||||
public enum CraterCapabilityHandler {
|
||||
ENERGY,
|
||||
ITEM,
|
||||
FLUID
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.blockentity.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 {
|
||||
|
||||
<T> Optional<T> getCapability(CraterCapabilityHandler handler, @Nullable Direction side);
|
||||
|
||||
}
|
@@ -1,82 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.creativetab;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper class to create custom creative tabs from modules
|
||||
*/
|
||||
public class CraterCreativeModeTab implements Supplier<CreativeModeTab> {
|
||||
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final Supplier<ItemStack> icon;
|
||||
private final String backgroundSuffix;
|
||||
private CreativeModeTab tab;
|
||||
private final ResourceKey<CreativeModeTab> resourceKey;
|
||||
|
||||
protected CraterCreativeModeTab(Builder builder) {
|
||||
this.resourceLocation = builder.location;
|
||||
this.icon = builder.stack;
|
||||
this.backgroundSuffix = builder.backgroundSuffix == null ? "" : builder.backgroundSuffix;
|
||||
this.resourceKey = ResourceKey.create(Registries.CREATIVE_MODE_TAB, this.resourceLocation);
|
||||
|
||||
CreativeTabRegistry.registerTab(this);
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation() {
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
public Supplier<ItemStack> getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getBackgroundSuffix() {
|
||||
return backgroundSuffix;
|
||||
}
|
||||
|
||||
public void setTab(CreativeModeTab tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
public ResourceKey<CreativeModeTab> getResourceKey() {
|
||||
return resourceKey;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final ResourceLocation location;
|
||||
private Supplier<ItemStack> stack;
|
||||
private String backgroundSuffix;
|
||||
|
||||
public Builder(ResourceLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public CraterCreativeModeTab.Builder setIcon(Supplier<ItemStack> icon) {
|
||||
stack = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CraterCreativeModeTab.Builder backgroundSuffix(String backgroundSuffix) {
|
||||
this.backgroundSuffix = backgroundSuffix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CraterCreativeModeTab build() {
|
||||
return new CraterCreativeModeTab(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreativeModeTab get() {
|
||||
return tab == null ? CreativeModeTabs.getDefaultTab() : tab;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A wrapped event to allow Block and Item Color Registration
|
||||
*/
|
||||
public class ColorRegistrationEvent {
|
||||
|
||||
public static class Blocks extends CraterEvent {
|
||||
|
||||
private final BlockColors colors;
|
||||
|
||||
public Blocks(BlockColors colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public BlockColors getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Items extends CraterEvent {
|
||||
|
||||
private final ItemColors colors;
|
||||
|
||||
public Items(ItemColors colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public ItemColors getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -17,14 +17,14 @@ public class CraterServerChatEvent extends CraterEvent {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public void setComponent(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public void setComponent(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@@ -5,7 +5,8 @@ import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CraterServerLifecycleEvent extends CraterEvent {
|
||||
|
||||
public CraterServerLifecycleEvent() {}
|
||||
public CraterServerLifecycleEvent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
@@ -27,19 +28,22 @@ public class CraterServerLifecycleEvent extends CraterEvent {
|
||||
|
||||
public static class Started extends CraterServerLifecycleEvent {
|
||||
|
||||
public Started() {}
|
||||
public Started() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Stopping extends CraterServerLifecycleEvent {
|
||||
|
||||
public Stopping() {}
|
||||
public Stopping() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Stopped extends CraterServerLifecycleEvent {
|
||||
|
||||
public Stopped() {}
|
||||
public Stopped() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +0,0 @@
|
||||
package com.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
|
||||
*/
|
||||
RenderType getCustomRenderType();
|
||||
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.rendering;
|
||||
|
||||
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
|
||||
*/
|
||||
BlockColor dyeHandler();
|
||||
|
||||
/**
|
||||
* Get the default Dye Color for Un-dyed states
|
||||
*/
|
||||
DyeColor defaultDyeColor();
|
||||
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.rendering;
|
||||
|
||||
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
|
||||
*/
|
||||
public DyeColor getColor(ItemStack stack);
|
||||
|
||||
}
|
@@ -6,7 +6,8 @@ import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
|
||||
/** Copied from Cloth Config Lite
|
||||
/**
|
||||
* Copied from Cloth Config Lite
|
||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/AbstractWidgetOption.java">...</a>
|
||||
*/
|
||||
public class AbstractConfigWidget<T, W extends AbstractWidget> extends BaseWidget<T> {
|
||||
|
@@ -6,7 +6,6 @@ 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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
|
@@ -54,7 +54,8 @@ public abstract class Option<T> extends AbstractContainerEventHandler {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void onAdd() {}
|
||||
public void onAdd() {
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
onAdd();
|
||||
|
@@ -10,7 +10,7 @@ import java.util.function.Function;
|
||||
* Copied from Cloth Config Lite
|
||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/TextFieldOption.java">...</a>
|
||||
*/
|
||||
public class TextConfigOption <T> extends AbstractConfigWidget<T, WrappedEditBox> {
|
||||
public class TextConfigOption<T> extends AbstractConfigWidget<T, WrappedEditBox> {
|
||||
|
||||
private final Function<T, String> toString;
|
||||
private final Function<String, T> fromString;
|
||||
|
@@ -10,7 +10,7 @@ import java.util.function.Function;
|
||||
* Copied from Cloth Config Lite
|
||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/ToggleOption.java">...</a>
|
||||
*/
|
||||
public class ToggleButton <T> extends AbstractConfigWidget<T, Button> {
|
||||
public class ToggleButton<T> extends AbstractConfigWidget<T, Button> {
|
||||
|
||||
private final List<T> options;
|
||||
private final Function<T, Component> toComponent;
|
||||
|
@@ -1,52 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client.registry;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper for registering Block and Item color handlers
|
||||
*/
|
||||
public class ClientRegistry {
|
||||
|
||||
/**
|
||||
* Register Block Color Handlers
|
||||
*
|
||||
* @param colors Existing block colors obtained from {@link com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent}
|
||||
* @param blocks The blocks registered for the module
|
||||
*/
|
||||
/*public static void registerBlockColors(@NotNull BlockColors colors, @NotNull RegistrationProvider<Block> blocks) {
|
||||
blocks.getEntries().forEach(blockRegistryObject -> {
|
||||
if (blockRegistryObject.get() instanceof DyableBlock dyableBlock) {
|
||||
colors.register(dyableBlock.dyeHandler(), (Block) dyableBlock);
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Register Item Color Handlers
|
||||
*
|
||||
* @param colors Existing item colors obtained from {@link com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent}
|
||||
* @param items The items registered for the module
|
||||
*/
|
||||
/*public static void registerItemColors(@NotNull ItemColors colors, @NotNull RegistrationProvider<Item> items) {
|
||||
items.getEntries().forEach(itemRegistryObject -> {
|
||||
if (itemRegistryObject.get() instanceof ItemDyable itemDyable) {
|
||||
colors.register(new ItemColorHandler(), (Item) itemDyable);
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Register a {@link net.minecraft.client.renderer.blockentity.BlockEntityRenderer} for a BlockEntity
|
||||
* @param blockEntityType The BlockEntity the renderer belongs to
|
||||
* @param blockEntityRendererFactory The renderer factory
|
||||
*/
|
||||
public static void registerBlockEntityRenderer(@NotNull BlockEntityType<? extends BlockEntity> blockEntityType, @NotNull BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
ClientPlatform.INSTANCE.registerBlockEntityRenderer(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client.rendering;
|
||||
|
||||
import com.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import com.hypherionmc.craterlib.util.RenderUtils;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Class for Dyable Items implementing a simple color handler
|
||||
*/
|
||||
public class ItemColorHandler implements ItemColor {
|
||||
|
||||
/***
|
||||
* Get the color for the Item/ItemStack
|
||||
* @param stack The ItemStack to read the color from
|
||||
* @param tintIndex No Comment
|
||||
* @return Integer value of the color
|
||||
*/
|
||||
@Override
|
||||
public int getColor(@NotNull ItemStack stack, int tintIndex) {
|
||||
return this.getColorFromStack(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color for the specific items stack, or return BLACK (0)
|
||||
*
|
||||
* @param stack The ItemStack to read the color from
|
||||
* @return Integer value of the color
|
||||
*/
|
||||
private int getColorFromStack(@NotNull ItemStack stack) {
|
||||
if (stack.getItem() instanceof ItemDyable itemDyable) {
|
||||
return RenderUtils.renderColorFromDye(itemDyable.getColor(stack));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.blockentity;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.ICraterCapProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A Wrapped Block Entity to incorporate CraterLib's universal capability provider
|
||||
*/
|
||||
public class CraterBlockEntity extends BlockEntity implements ICraterCapProvider {
|
||||
|
||||
public CraterBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state) {
|
||||
super(blockEntityType, pos, state);
|
||||
}
|
||||
|
||||
public void sendUpdates() {
|
||||
level.blockEntityChanged(this.getBlockPos());
|
||||
level.sendBlockUpdated(this.getBlockPos(), level.getBlockState(this.getBlockPos()), level.getBlockState(this.getBlockPos()), 3);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientboundBlockEntityDataPacket getUpdatePacket() {
|
||||
return ClientboundBlockEntityDataPacket.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag() {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
saveAdditional(compoundTag);
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapability(CraterCapabilityHandler handler, @Nullable Direction side) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.blockentity;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CraterFluidHelper;
|
||||
import com.hypherionmc.craterlib.core.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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A wrapped BlockEntity containing a fluid tank
|
||||
*/
|
||||
public class FluidContainerBlockEntity extends CraterBlockEntity {
|
||||
|
||||
public final CraterFluidTank fluidTank;
|
||||
|
||||
public FluidContainerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, int capacity) {
|
||||
super(blockEntityType, pos, state);
|
||||
fluidTank = CraterFluidHelper.INSTANCE.createFluidTank(capacity);
|
||||
}
|
||||
|
||||
public FluidContainerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, int capacity, Fluid... validFluids) {
|
||||
super(blockEntityType, pos, state);
|
||||
fluidTank = CraterFluidHelper.INSTANCE.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(CraterCapabilityHandler handler, @Nullable Direction side) {
|
||||
if (handler == CraterCapabilityHandler.FLUID) {
|
||||
return (Optional<T>) Optional.of(fluidTank);
|
||||
}
|
||||
return super.getCapability(handler, side);
|
||||
}
|
||||
|
||||
public CraterFluidTank getFluidTank() {
|
||||
return fluidTank;
|
||||
}
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.item;
|
||||
|
||||
import com.hypherionmc.craterlib.api.rendering.DyableBlock;
|
||||
import com.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.core.platform.Environment;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Base Item for Blocks that implement @link {DyableBlock}.
|
||||
*/
|
||||
public class BlockItemDyable extends BlockItem implements ItemDyable {
|
||||
|
||||
public BlockItemDyable(Block block, Properties properties) {
|
||||
super(block, properties);
|
||||
|
||||
if (ModloaderEnvironment.INSTANCE.getEnvironment() == Environment.CLIENT) {
|
||||
ClientPlatform.INSTANCE.registerItemProperty(this, "color");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Item Color from the block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DyeColor getColor(ItemStack stack) {
|
||||
return this.getColorFromNBT(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getName(ItemStack stack) {
|
||||
return Component.translatable(
|
||||
this.getDescriptionId(),
|
||||
WordUtils.capitalizeFully(getColorFromNBT(
|
||||
stack).getName().replace("_", " ")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public DyeColor getColorFromNBT(ItemStack stack) {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
if (tag.contains("color")) {
|
||||
return DyeColor.byName(tag.getString("color"), DyeColor.BLACK);
|
||||
} else {
|
||||
if (this.getBlock() instanceof DyableBlock dyableBlock) {
|
||||
return dyableBlock.defaultDyeColor();
|
||||
}
|
||||
}
|
||||
return DyeColor.BLACK;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected BlockState getPlacementState(BlockPlaceContext ctx) {
|
||||
BlockState state = this.getBlock().getStateForPlacement(ctx);
|
||||
if (state != null && state.getBlock() instanceof DyableBlock) {
|
||||
Property property = state.getBlock().getStateDefinition().getProperty("color");
|
||||
if (property != null) {
|
||||
state = state.setValue(property, getColorFromNBT(ctx.getItemInHand()));
|
||||
}
|
||||
}
|
||||
return state != null && this.canPlace(ctx, state) ? state : null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.item;
|
||||
|
||||
import com.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Custom Water Bottle item that supports Dye and can be used as Dye
|
||||
*/
|
||||
public class DyableWaterBottle extends DyeItem implements ItemDyable {
|
||||
|
||||
private final DyeColor color;
|
||||
private final boolean isGlowing;
|
||||
|
||||
public DyableWaterBottle(DyeColor color, boolean isGlowing, Properties properties) {
|
||||
super(color, properties);
|
||||
this.color = color;
|
||||
this.isGlowing = isGlowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally this is used for enchanted items, in this case, it's used to check if the fluid is a glowing fluid
|
||||
*
|
||||
* @param stack
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
return this.isGlowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color of the item for the Color Handler
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DyeColor getColor(ItemStack stack) {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is basically the same as the vanilla method for water bottles
|
||||
*
|
||||
* @param stack
|
||||
* @param level
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) {
|
||||
Player playerEntity;
|
||||
Player playerEntity2 = playerEntity = user instanceof Player ? (Player) user : null;
|
||||
if (playerEntity instanceof ServerPlayer) {
|
||||
CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer) playerEntity, stack);
|
||||
}
|
||||
if (!level.isClientSide()) {
|
||||
List<MobEffectInstance> list = PotionUtils.getMobEffects(stack);
|
||||
for (MobEffectInstance statusEffectInstance : list) {
|
||||
if (statusEffectInstance.getEffect().isInstantenous()) {
|
||||
statusEffectInstance.getEffect().applyInstantenousEffect(playerEntity, playerEntity, user, statusEffectInstance.getAmplifier(), 1.0);
|
||||
continue;
|
||||
}
|
||||
user.addEffect(new MobEffectInstance(statusEffectInstance));
|
||||
}
|
||||
if (stack.getItem() == this && isGlowing) {
|
||||
user.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 3600));
|
||||
}
|
||||
}
|
||||
if (playerEntity != null) {
|
||||
playerEntity.awardStat(Stats.ITEM_USED.get(this));
|
||||
if (!playerEntity.getAbilities().instabuild) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
}
|
||||
if (playerEntity == null || !playerEntity.getAbilities().instabuild) {
|
||||
if (stack.isEmpty()) {
|
||||
return new ItemStack(Items.GLASS_BOTTLE);
|
||||
}
|
||||
if (playerEntity != null) {
|
||||
playerEntity.getInventory().add(new ItemStack(Items.GLASS_BOTTLE));
|
||||
}
|
||||
}
|
||||
level.gameEvent(user, GameEvent.DRINK, user.getOnPos());
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack) {
|
||||
return 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UseAnim getUseAnimation(ItemStack stack) {
|
||||
return UseAnim.DRINK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
return ItemUtils.startUsingInstantly(level, player, hand);
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.item;
|
||||
|
||||
import com.hypherionmc.craterlib.api.rendering.ItemDyable;
|
||||
import net.minecraft.world.item.BucketItem;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A custom water bucket that supports Dye Colors
|
||||
*/
|
||||
public class DyableWaterBucket extends BucketItem implements ItemDyable {
|
||||
|
||||
private final DyeColor color;
|
||||
private final boolean isGlowing;
|
||||
|
||||
public DyableWaterBucket(Fluid fluid, Properties properties, DyeColor color, boolean isGlowing) {
|
||||
super(fluid, properties);
|
||||
this.color = color;
|
||||
this.isGlowing = isGlowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally this is used for enchanted items, in this case, it's used to check if the fluid is a glowing fluid
|
||||
*
|
||||
* @param stack
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
return this.isGlowing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getColor(ItemStack stack) {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public boolean isGlowing() {
|
||||
return isGlowing;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common.particles;
|
||||
|
||||
import net.minecraft.core.particles.SimpleParticleType;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper Class for exposing a hidden constructor in the vanilla particle type
|
||||
*/
|
||||
public class WrappedSimpleParticleType extends SimpleParticleType {
|
||||
|
||||
public WrappedSimpleParticleType(boolean alwaysShow) {
|
||||
super(alwaysShow);
|
||||
}
|
||||
}
|
@@ -162,6 +162,7 @@ public class ModuleConfig {
|
||||
|
||||
/**
|
||||
* Get the name of the Config File
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getConfigName() {
|
||||
@@ -170,6 +171,7 @@ public class ModuleConfig {
|
||||
|
||||
/**
|
||||
* Get the MODID of the Module the config is registered to
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getModId() {
|
||||
|
@@ -12,9 +12,8 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class CraterEventBus {
|
||||
|
||||
private static final Logger LOGGER = CraterConstants.LOG;
|
||||
|
||||
public static final CraterEventBus INSTANCE = new CraterEventBus();
|
||||
private static final Logger LOGGER = CraterConstants.LOG;
|
||||
private final Map<Class<? extends CraterEvent>, List<ListenerContainer>> events = new HashMap<>();
|
||||
|
||||
public void postEvent(CraterEvent event) {
|
||||
@@ -157,13 +156,6 @@ public final class CraterEventBus {
|
||||
collectMethodAnnotations(this.isStatic ? null : this.parentObject.getClass(), this.method, this.annotations);
|
||||
}
|
||||
|
||||
protected Class<?> tryGetParentClass() {
|
||||
if (this.parentObject instanceof Class<?>) {
|
||||
return (Class<?>) this.parentObject;
|
||||
}
|
||||
return this.parentObject.getClass();
|
||||
}
|
||||
|
||||
protected static void collectMethodAnnotations(Class<?> c, Method m, List<Annotation> addToList) {
|
||||
try {
|
||||
addToList.addAll(Arrays.asList(m.getAnnotations()));
|
||||
@@ -173,10 +165,19 @@ public final class CraterEventBus {
|
||||
try {
|
||||
Method sm = sc.getMethod(m.getName(), m.getParameterTypes());
|
||||
collectMethodAnnotations(sc, sm, addToList);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
protected Class<?> tryGetParentClass() {
|
||||
if (this.parentObject instanceof Class<?>) {
|
||||
return (Class<?>) this.parentObject;
|
||||
}
|
||||
return this.parentObject.getClass();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -186,11 +187,6 @@ public final class CraterEventBus {
|
||||
protected final int priority;
|
||||
protected final Class<? extends CraterEvent> eventType;
|
||||
|
||||
protected static EventMethod tryCreateFrom(AnalyzedMethod method) {
|
||||
EventMethod em = new EventMethod(method);
|
||||
return (em.eventType != null) ? em : null;
|
||||
}
|
||||
|
||||
protected EventMethod(AnalyzedMethod method) {
|
||||
|
||||
super();
|
||||
@@ -205,6 +201,11 @@ public final class CraterEventBus {
|
||||
|
||||
}
|
||||
|
||||
protected static EventMethod tryCreateFrom(AnalyzedMethod method) {
|
||||
EventMethod em = new EventMethod(method);
|
||||
return (em.eventType != null) ? em : null;
|
||||
}
|
||||
|
||||
protected Class<? extends CraterEvent> tryGetEventType() {
|
||||
try {
|
||||
if (this.method != null) {
|
||||
|
@@ -1,15 +1,10 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -18,10 +13,6 @@ public interface ClientPlatform {
|
||||
|
||||
public final ClientPlatform INSTANCE = ServiceUtil.load(ClientPlatform.class);
|
||||
|
||||
void registerItemProperty(@NotNull BlockItemDyable item, @NotNull String property);
|
||||
|
||||
//void registerCustomRenderTypes(@NotNull Collection<RegistryObject<Block>> blocks);
|
||||
|
||||
Minecraft getClientInstance();
|
||||
|
||||
Player getClientPlayer();
|
||||
@@ -29,7 +20,4 @@ public interface ClientPlatform {
|
||||
Level getClientLevel();
|
||||
|
||||
Connection getClientConnection();
|
||||
|
||||
void registerBlockEntityRenderer(@NotNull BlockEntityType<? extends BlockEntity> blockEntityType, @NotNull BlockEntityRendererProvider blockEntityRendererFactory);
|
||||
|
||||
}
|
||||
|
@@ -1,22 +1,8 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -33,13 +19,4 @@ public interface CommonPlatform {
|
||||
|
||||
MinecraftServer getMCServer();
|
||||
|
||||
default void openMenu(ServerPlayer player, MenuProvider menuProvider) {
|
||||
this.openMenu(player, menuProvider, null);
|
||||
}
|
||||
|
||||
void openMenu(ServerPlayer player, MenuProvider menu, @Nullable Consumer<FriendlyByteBuf> initialData);
|
||||
|
||||
<T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<Integer, Inventory, FriendlyByteBuf, T> constructor);
|
||||
|
||||
<T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CraterCapabilityHandler capability);
|
||||
}
|
||||
|
@@ -1,36 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public interface CraterFluidHelper {
|
||||
|
||||
public CraterFluidHelper INSTANCE = ServiceUtil.load(CraterFluidHelper.class);
|
||||
|
||||
CraterFluidTank createFluidTank(int capacity);
|
||||
|
||||
CraterFluidTank createFluidTank(int capacity, Fluid... validFluids);
|
||||
|
||||
boolean interactWithFluidHandler(Player player, InteractionHand hand, ICraterFluidHandler fluidHandler);
|
||||
|
||||
boolean interactWithFluidHandler(@NotNull Player player, @NotNull InteractionHand hand, @NotNull Level level, @NotNull BlockPos pos, @Nullable Direction side);
|
||||
|
||||
TextureAtlasSprite getFluidTexture(FluidHolder fluidHolder);
|
||||
|
||||
int getFluidColor(Fluid fluid);
|
||||
|
||||
}
|
@@ -13,12 +13,20 @@ public interface ModloaderEnvironment {
|
||||
public final ModloaderEnvironment INSTANCE = ServiceUtil.load(ModloaderEnvironment.class);
|
||||
|
||||
boolean isFabric();
|
||||
|
||||
String getGameVersion();
|
||||
|
||||
File getGameFolder();
|
||||
|
||||
File getConfigFolder();
|
||||
|
||||
File getModsFolder();
|
||||
|
||||
Environment getEnvironment();
|
||||
|
||||
boolean isModLoaded(String modid);
|
||||
|
||||
boolean isDevEnv();
|
||||
|
||||
int getModCount();
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ public interface DiscordRPC extends Library {
|
||||
|
||||
/**
|
||||
* Open a New RPC Connection
|
||||
*
|
||||
* @param applicationId The ID of the Application the RPC is tied to
|
||||
* @param handlers Optional Event Callback Handlers
|
||||
* @param autoRegister Auto Register the running game
|
||||
@@ -40,6 +41,7 @@ public interface DiscordRPC extends Library {
|
||||
|
||||
/**
|
||||
* Update the Rich Presence
|
||||
*
|
||||
* @param struct Constructed {@link DiscordRichPresence}
|
||||
*/
|
||||
void Discord_UpdatePresence(@Nullable DiscordRichPresence struct);
|
||||
@@ -51,6 +53,7 @@ public interface DiscordRPC extends Library {
|
||||
|
||||
/**
|
||||
* Respond to Join/Spectate callback
|
||||
*
|
||||
* @param userid The Discord User ID of the user that initiated the request
|
||||
* @param reply Reply to the request. See {@link DiscordReply}
|
||||
*/
|
||||
@@ -58,6 +61,7 @@ public interface DiscordRPC extends Library {
|
||||
|
||||
/**
|
||||
* Replace the already registered {@link DiscordEventHandlers}
|
||||
*
|
||||
* @param handlers The new handlers to apply
|
||||
*/
|
||||
void Discord_UpdateHandlers(@Nullable DiscordEventHandlers handlers);
|
||||
@@ -65,15 +69,17 @@ public interface DiscordRPC extends Library {
|
||||
/**
|
||||
* Register the executable of the application/game
|
||||
* Only applicable when autoRegister is set to false
|
||||
*
|
||||
* @param applicationId The Application ID
|
||||
* @param command The Launch command of the game
|
||||
*
|
||||
* <p>
|
||||
* NB: THIS DOES NOT WORK WITH MINECRAFT
|
||||
*/
|
||||
void Discord_Register(String applicationId, String command);
|
||||
|
||||
/**
|
||||
* Register the Steam executable of the application/game
|
||||
*
|
||||
* @param applicationId The Application ID
|
||||
* @param steamId The Steam ID of the application/game
|
||||
*/
|
||||
|
@@ -75,6 +75,10 @@ public class DiscordRichPresence extends Structure {
|
||||
// Unused
|
||||
public int instance;
|
||||
|
||||
public DiscordRichPresence() {
|
||||
setStringEncoding("UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* DO NOT TOUCH THIS... EVER!
|
||||
*/
|
||||
@@ -104,10 +108,6 @@ public class DiscordRichPresence extends Structure {
|
||||
);
|
||||
}
|
||||
|
||||
public DiscordRichPresence() {
|
||||
setStringEncoding("UTF-8");
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final DiscordRichPresence rpc;
|
||||
|
||||
|
@@ -10,6 +10,7 @@ public interface DisconnectedCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when RPC disconnected
|
||||
*
|
||||
* @param errorCode Error code if any
|
||||
* @param message Details about the disconnection
|
||||
*/
|
||||
|
@@ -10,6 +10,7 @@ public interface ErroredCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when an RPC error occurs
|
||||
*
|
||||
* @param errorCode Error code if any
|
||||
* @param message Details about the error
|
||||
*/
|
||||
|
@@ -10,6 +10,7 @@ public interface JoinGameCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when someone joins a game from {@link JoinRequestCallback}
|
||||
*
|
||||
* @param joinSecret Secret or Password required to let the player join the game
|
||||
*/
|
||||
void apply(String joinSecret);
|
||||
|
@@ -11,6 +11,7 @@ public interface JoinRequestCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when someone clicks on the Join Game button
|
||||
*
|
||||
* @param user The Discord User trying to join your game
|
||||
* @see DiscordUser
|
||||
*/
|
||||
|
@@ -11,6 +11,7 @@ public interface ReadyCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when the RPC is connected and ready to be used
|
||||
*
|
||||
* @param user The user the RPC is displayed on
|
||||
* @see DiscordUser
|
||||
*/
|
||||
|
@@ -10,6 +10,7 @@ public interface SpectateGameCallback extends Callback {
|
||||
|
||||
/**
|
||||
* Called when joining the game
|
||||
*
|
||||
* @param spectateSecret Secret or Password required to let the player spectate
|
||||
*/
|
||||
void apply(String spectateSecret);
|
||||
|
@@ -24,6 +24,7 @@ public class RPCButton implements Serializable {
|
||||
|
||||
/**
|
||||
* Create a new RPC Button
|
||||
*
|
||||
* @param label The label of the button
|
||||
* @param url The URL the button will open when clicked
|
||||
* @return The constructed button
|
||||
|
@@ -1,100 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.energy;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
/***
|
||||
* @author HypherionSA
|
||||
* Loosely based on the Forge Energy System
|
||||
*/
|
||||
public class CustomEnergyStorage implements ICraterEnergyStorage {
|
||||
|
||||
protected int powerLevel;
|
||||
protected int powerCapacity;
|
||||
protected int maxInput;
|
||||
protected int maxOutput;
|
||||
|
||||
public CustomEnergyStorage(int capacity) {
|
||||
this(capacity, capacity, capacity, 0);
|
||||
}
|
||||
|
||||
public CustomEnergyStorage(int powerCapacity, int maxTransfer) {
|
||||
this(powerCapacity, maxTransfer, maxTransfer, 0);
|
||||
}
|
||||
|
||||
public CustomEnergyStorage(int powerCapacity, int maxInput, int maxOutput) {
|
||||
this(powerCapacity, maxInput, maxOutput, 0);
|
||||
}
|
||||
|
||||
public CustomEnergyStorage(int capacity, int maxInput, int maxOutput, int initialPower) {
|
||||
this.powerLevel = initialPower;
|
||||
this.maxInput = maxInput;
|
||||
this.maxOutput = maxOutput;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
public int receiveEnergyInternal(int toReceive, boolean test) {
|
||||
int energyReceived = Math.min(this.powerCapacity - this.powerLevel, Math.min(this.maxInput, toReceive));
|
||||
if (!test)
|
||||
this.powerLevel += energyReceived;
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int toReceive, boolean test) {
|
||||
if (this.maxInput < 1) {
|
||||
return 0;
|
||||
}
|
||||
return this.receiveEnergyInternal(toReceive, test);
|
||||
}
|
||||
|
||||
public int extractEnergyInternal(int toExtract, boolean test) {
|
||||
int energyExtracted = Math.min(this.powerLevel, Math.min(this.powerCapacity, toExtract));
|
||||
if (!test)
|
||||
this.powerLevel -= energyExtracted;
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int toExtract, boolean test) {
|
||||
if (this.maxOutput < 1) {
|
||||
return 0;
|
||||
}
|
||||
int energyExtracted = Math.min(this.powerLevel, Math.min(this.maxOutput, toExtract));
|
||||
if (!test)
|
||||
this.powerLevel -= energyExtracted;
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.energy;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public interface ICraterEnergyStorage {
|
||||
|
||||
default CompoundTag writeNBT(CompoundTag tag) { return tag; }
|
||||
default void readNBT(CompoundTag tag) {}
|
||||
|
||||
int receiveEnergy(int toReceive, boolean test);
|
||||
int extractEnergy(int toExtract, boolean test);
|
||||
|
||||
int getPowerLevel();
|
||||
|
||||
int getMaxInput();
|
||||
|
||||
int getMaxOutput();
|
||||
|
||||
int getPowerCapacity();
|
||||
|
||||
}
|
@@ -1,151 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.fluid;
|
||||
|
||||
import com.hypherionmc.craterlib.util.FluidUtils;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A cross Modloader FluidTank implementation
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.fluid;
|
||||
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Cross Modloader "FluidStack" implementation
|
||||
*/
|
||||
public class FluidHolder {
|
||||
|
||||
private final 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());
|
||||
}
|
||||
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.fluid;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Cross modloader fluid handler implementation
|
||||
*/
|
||||
public interface ICraterFluidHandler {
|
||||
|
||||
enum FluidAction {
|
||||
EXECUTE,
|
||||
SIMULATE;
|
||||
|
||||
public boolean simulate() {
|
||||
return this == SIMULATE;
|
||||
}
|
||||
|
||||
public boolean execute() {
|
||||
return this == EXECUTE;
|
||||
}
|
||||
}
|
||||
|
||||
int insert(FluidHolder fluidHolder, CraterFluidTank.FluidAction action);
|
||||
FluidHolder extract(FluidHolder fluidHolder, CraterFluidTank.FluidAction action);
|
||||
FluidHolder extract(int amount, CraterFluidTank.FluidAction action);
|
||||
boolean isTankEmpty();
|
||||
FluidHolder getFluidInTank();
|
||||
int getTankLevel();
|
||||
int getTankCapacity();
|
||||
|
||||
default CompoundTag writeToNBT(CompoundTag tag) { return tag; }
|
||||
|
||||
default void readFromNBT(CompoundTag tag) {};
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.internal;
|
||||
|
||||
import com.hypherionmc.craterlib.api.creativetab.CraterCreativeModeTab;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A helper class to make registering creative tabs easier across modloaders
|
||||
*/
|
||||
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) {
|
||||
if (item != null) {
|
||||
TAB_ITEMS.add(Pair.of(tab, item));
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTab(CraterCreativeModeTab tab) {
|
||||
TABS.add(tab);
|
||||
}
|
||||
|
||||
public static List<CraterCreativeModeTab> getTabs() {
|
||||
return TABS;
|
||||
}
|
||||
|
||||
public static List<Pair<CraterCreativeModeTab, Supplier<? extends ItemLike>>> getTabItems() {
|
||||
return TAB_ITEMS;
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
package com.hypherionmc.craterlib.core.systems.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.Clearable;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* A crossmodloader inventory implementation
|
||||
*/
|
||||
public class SimpleInventory implements Clearable {
|
||||
|
||||
private final SimpleContainer itemHandler;
|
||||
private final int size;
|
||||
|
||||
private final int stackSize;
|
||||
|
||||
public SimpleInventory(int size, int maxStackSize) {
|
||||
itemHandler = new SimpleContainer(size) {
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStackSize;
|
||||
}
|
||||
};
|
||||
this.size = size;
|
||||
this.stackSize = maxStackSize;
|
||||
}
|
||||
|
||||
private static void copyToInv(NonNullList<ItemStack> src, Container dest) {
|
||||
Preconditions.checkArgument(src.size() == dest.getContainerSize());
|
||||
for (int i = 0; i < src.size(); i++) {
|
||||
dest.setItem(i, src.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private static NonNullList<ItemStack> copyFromInv(Container inv) {
|
||||
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < inv.getContainerSize(); i++) {
|
||||
ret.set(i, inv.getItem(i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void readNBT(CompoundTag tag) {
|
||||
NonNullList<ItemStack> tmp = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
ContainerHelper.loadAllItems(tag, tmp);
|
||||
copyToInv(tmp, itemHandler);
|
||||
}
|
||||
|
||||
public void writeNBT(CompoundTag tag) {
|
||||
ContainerHelper.saveAllItems(tag, copyFromInv(itemHandler));
|
||||
}
|
||||
|
||||
public final int inventorySize() {
|
||||
return getItemHandler().getContainerSize();
|
||||
}
|
||||
|
||||
public int getStackSize() {
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
getItemHandler().clearContent();
|
||||
}
|
||||
|
||||
public final Container getItemHandler() {
|
||||
return itemHandler;
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
/**
|
||||
* So, if you got here, most probably you want to see the registration system of this mod.
|
||||
* Well, you are in the wrong place.
|
||||
* This mod uses <a href="https://github.com/Matyrobbrt/RegistrationUtils">RegistrationUtils</a> for
|
||||
* all its registration needs.
|
||||
*/
|
||||
package com.hypherionmc.craterlib.core.systems.reg;
|
@@ -1,27 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin.colors;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Mixin to accommodate Block Color Registration across multiple Modloaders
|
||||
*/
|
||||
@Mixin(BlockColors.class)
|
||||
public class BlockColorsMixin {
|
||||
|
||||
/**
|
||||
* Inject into Vanilla code to fire off our event
|
||||
*/
|
||||
@Inject(method = "createDefault", at = @At("RETURN"))
|
||||
private static void injectBlockColors(CallbackInfoReturnable<BlockColors> cir) {
|
||||
ColorRegistrationEvent.Blocks blockEvent = new ColorRegistrationEvent.Blocks(cir.getReturnValue());
|
||||
CraterEventBus.INSTANCE.postEvent(blockEvent);
|
||||
}
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin.colors;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Mixin to accommodate Item Color Registration across multiple Modloaders
|
||||
*/
|
||||
@Mixin(ItemColors.class)
|
||||
public class ItemColorsMixin {
|
||||
|
||||
/**
|
||||
* Inject into Vanilla code to fire off our event
|
||||
* @param cir
|
||||
*/
|
||||
@Inject(method = "createDefault", at = @At("RETURN"))
|
||||
private static void injectItemColors(BlockColors $$0, CallbackInfoReturnable<ItemColors> cir) {
|
||||
ColorRegistrationEvent.Items itemColorEvent = new ColorRegistrationEvent.Items(cir.getReturnValue());
|
||||
CraterEventBus.INSTANCE.postEvent(itemColorEvent);
|
||||
}
|
||||
|
||||
}
|
@@ -10,7 +10,6 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Commands.class)
|
||||
public class CommandMixin {
|
||||
|
@@ -14,7 +14,7 @@ public class LivingEntityMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((LivingEntity)(Object) this), damageSource);
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((LivingEntity) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
|
@@ -15,7 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(PlayerAdvancements.class)
|
||||
public class PlayerAdvancementsMixin {
|
||||
|
||||
@Shadow private ServerPlayer player;
|
||||
@Shadow
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
private void injectAdvancementEvent(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
|
@@ -14,7 +14,7 @@ public class PlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((Player)(Object) this), damageSource);
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((Player) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
|
@@ -14,7 +14,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketListenerImplMixin {
|
||||
|
||||
@Shadow public ServerPlayer player;
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void injectChatEvent(PlayerChatMessage chatMessage, CallbackInfo ci) {
|
||||
|
@@ -14,7 +14,7 @@ public class ServerPlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((ServerPlayer)(Object) this), damageSource);
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((ServerPlayer) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
|
@@ -14,7 +14,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
|
||||
@Shadow @Nullable
|
||||
@Shadow
|
||||
@Nullable
|
||||
public Screen screen;
|
||||
|
||||
@Inject(method = "setScreen", at = @At(value = "TAIL"))
|
||||
|
@@ -1,22 +0,0 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Helper class to create light levels from BlockState values
|
||||
*/
|
||||
public class BlockStateUtils {
|
||||
|
||||
public static ToIntFunction<BlockState> lightLevelFromLitBlockState(int litLevel) {
|
||||
return state -> state.getValue(BlockStateProperties.LIT) ? litLevel : 0;
|
||||
}
|
||||
|
||||
public static ToIntFunction<BlockState> lightLevelFromPoweredBlockState(int litLevel) {
|
||||
return state -> state.getValue(BlockStateProperties.POWERED) ? litLevel : 0;
|
||||
}
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import com.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class ColorPropertyFunction implements ClampedItemPropertyFunction {
|
||||
|
||||
private final BlockItemDyable item;
|
||||
|
||||
public ColorPropertyFunction(BlockItemDyable item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float call(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
|
||||
return Mth.clamp(this.unclampedCall(itemStack, clientLevel, livingEntity, i), 0.0F, 15.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float unclampedCall(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
|
||||
DyeColor color = item.getColorFromNBT(itemStack);
|
||||
return color.getId();
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package com.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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Utility class for interacting with fluids across modloaders
|
||||
*/
|
||||
public class FluidUtils {
|
||||
|
||||
public static int fluidColorFromDye(DyeColor color) {
|
||||
return color.getMapColor().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")));
|
||||
}
|
||||
|
||||
}
|
@@ -41,6 +41,15 @@ public class RenderUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMapColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static int alphaColorFromDye(DyeColor color, float alpha) {
|
||||
float[] colors = color.getTextureDiffuseColors();
|
||||
return new Color(colors[0], colors[1], colors[2], alpha).getRGB();
|
||||
}
|
||||
|
||||
public static class ARGB32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
@@ -58,13 +67,4 @@ public class RenderUtils {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMapColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static int alphaColorFromDye(DyeColor color, float alpha) {
|
||||
float[] colors = color.getTextureDiffuseColors();
|
||||
return new Color(colors[0], colors[1], colors[2], alpha).getRGB();
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ public class ServiceUtil {
|
||||
|
||||
/**
|
||||
* Try to load a service
|
||||
*
|
||||
* @param clazz The service class type to load
|
||||
* @return The loaded class
|
||||
*/
|
||||
|
@@ -1,4 +0,0 @@
|
||||
accessWidener v1 named
|
||||
|
||||
accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction;)V
|
||||
accessible method net/minecraft/client/renderer/blockentity/BlockEntityRenderers register (Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/client/renderer/blockentity/BlockEntityRendererProvider;)V
|
@@ -6,8 +6,6 @@
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"colors.BlockColorsMixin",
|
||||
"colors.ItemColorsMixin",
|
||||
"events.PlayerMixin",
|
||||
"events.client.ClientLevelMixin",
|
||||
"events.client.MinecraftMixin",
|
||||
|
@@ -36,7 +36,6 @@ shadowJar {
|
||||
unimined.minecraft {
|
||||
fabric {
|
||||
loader fabric_loader
|
||||
accessWidener(project(":Common").file("src/main/resources/${mod_id}.aw"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,9 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.event.annot.CraterEventListener;
|
||||
import com.hypherionmc.craterlib.core.systems.internal.CreativeTabRegistry;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class CraterLibClientInitializer implements ClientModInitializer {
|
||||
|
||||
@@ -26,23 +16,4 @@ public class CraterLibClientInitializer implements ClientModInitializer {
|
||||
|
||||
CraterEventBus.INSTANCE.registerEventListener(CraterLibClientInitializer.class);
|
||||
}
|
||||
|
||||
@CraterEventListener
|
||||
public static void lateInitEvent(LateInitEvent event) {
|
||||
CreativeTabRegistry.getTabs().forEach(tab -> {
|
||||
CreativeModeTab finalTab = Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, tab.getResourceKey(), FabricItemGroup.builder()
|
||||
.title(Component.translatable("itemGroup." +
|
||||
tab.getResourceLocation().toString().replace(":", ".")
|
||||
))
|
||||
.icon(tab.getIcon())
|
||||
.build());
|
||||
|
||||
tab.setTab(finalTab);
|
||||
|
||||
ItemGroupEvents.modifyEntriesEvent(tab.getResourceKey()).register(entries -> CreativeTabRegistry
|
||||
.getTabItems()
|
||||
.stream().filter(t -> t.getLeft().get() == finalTab && t.getRight() != null)
|
||||
.map(Pair::getRight).forEach(itm -> entries.accept(itm.get())));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +1,16 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.util.ColorPropertyFunction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class FabricClientPlatform implements ClientPlatform {
|
||||
|
||||
@Override
|
||||
public void registerItemProperty(@NotNull BlockItemDyable item, @NotNull String property) {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
ItemProperties.register(item, new ResourceLocation(property), new ColorPropertyFunction(item));
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void registerCustomRenderTypes(Collection<RegistryObject<Block>> blocks) {
|
||||
blocks.forEach(blk -> {
|
||||
if (blk.get() instanceof CustomRenderType type) {
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(blk.get(), type.getCustomRenderType());
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public Minecraft getClientInstance() {
|
||||
return Minecraft.getInstance();
|
||||
@@ -57,9 +30,4 @@ public class FabricClientPlatform implements ClientPlatform {
|
||||
public Connection getClientConnection() {
|
||||
return Minecraft.getInstance().getConnection().getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockEntityRenderer(@NotNull BlockEntityType<? extends BlockEntity> blockEntityType, @NotNull BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
BlockEntityRenderers.register(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
}
|
||||
|
@@ -1,94 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client.gui.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.systems.fluid.FluidTank;
|
||||
import com.hypherionmc.craterlib.util.RenderUtils;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
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.function.Supplier;
|
||||
|
||||
/**
|
||||
* Modified from <a href="https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.18.x/enderio-machines/src/main/java/com/enderio/machines/client/FluidStackWidget.java">...</a>
|
||||
*/
|
||||
public class FluidStackWidget extends AbstractWidget {
|
||||
|
||||
private final Screen displayOn;
|
||||
private final Supplier<FluidTank> getFluid;
|
||||
|
||||
private final String toolTipTitle;
|
||||
|
||||
public FluidStackWidget(Screen displayOn, Supplier<FluidTank> getFluid, int pX, int pY, int pWidth, int pHeight, String tooltipTitle) {
|
||||
super(pX, pY, pWidth, pHeight, Component.empty());
|
||||
this.displayOn = displayOn;
|
||||
this.getFluid = getFluid;
|
||||
this.toolTipTitle = tooltipTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
FluidTank fluidTank = getFluid.get();
|
||||
if (!fluidTank.getResource().isBlank()) {
|
||||
FluidVariant fluidStack = fluidTank.getResource();
|
||||
TextureAtlasSprite still = FluidVariantRendering.getSprite(fluidStack);
|
||||
if (still != null) {
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
||||
|
||||
int color = FluidVariantRendering.getColor(fluidStack);
|
||||
RenderSystem.setShaderColor(
|
||||
RenderUtils.ARGB32.red(color) / 255.0F,
|
||||
RenderUtils.ARGB32.green(color) / 255.0F,
|
||||
RenderUtils.ARGB32.blue(color) / 255.0F,
|
||||
RenderUtils.ARGB32.alpha(color) / 255.0F);
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
long stored = fluidTank.getAmount();
|
||||
float capacity = fluidTank.getCapacity();
|
||||
float filledVolume = stored / capacity;
|
||||
int renderableHeight = (int) (filledVolume * height);
|
||||
|
||||
int atlasWidth = (int) (still.getX() / (still.getU1() - still.getU0()));
|
||||
int atlasHeight = (int) (still.getY() / (still.getV1() - still.getV0()));
|
||||
|
||||
matrices.pose().pushPose();
|
||||
matrices.pose().translate(0, height - 16, 0);
|
||||
for (int i = 0; i < Math.ceil(renderableHeight / 16f); i++) {
|
||||
int drawingHeight = Math.min(16, renderableHeight - 16 * i);
|
||||
int notDrawingHeight = 16 - drawingHeight;
|
||||
// TODO Double Check this
|
||||
matrices.blit(TextureAtlas.LOCATION_BLOCKS, getX(), getY() + notDrawingHeight, 0, still.getU0() * atlasWidth, still.getV0() * atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
matrices.pose().translate(0, -16, 0);
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
matrices.pose().popPose();
|
||||
}
|
||||
//renderToolTip(matrices, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Fix Tooltips
|
||||
/*@Override
|
||||
public void renderToolTip(PoseStack poseStack, int mouseX, int mouseY) {
|
||||
if (this.visible && this.isFocused() && isHoveredOrFocused()) {
|
||||
displayOn.renderTooltip(poseStack, Arrays.asList(LangUtils.getTooltipTitle(toolTipTitle), Component.literal((int) (((float) this.getFluid.get().getAmount() / this.getFluid.get().getCapacity()) * 100) + "%")), Optional.empty(), mouseX, mouseY);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +1,9 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.ICraterCapProvider;
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.network.FabricNetworkHandler;
|
||||
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.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
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.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -41,40 +21,4 @@ public class FabricCommonPlatform implements CommonPlatform {
|
||||
public MinecraftServer getMCServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openMenu(ServerPlayer player, MenuProvider menu, Consumer<FriendlyByteBuf> initialData) {
|
||||
ExtendedScreenHandlerFactory factory = new ExtendedScreenHandlerFactory() {
|
||||
@Override
|
||||
public void writeScreenOpeningData(ServerPlayer player, FriendlyByteBuf buf) {
|
||||
initialData.accept(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getDisplayName() {
|
||||
return menu.getDisplayName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int i, @NotNull Inventory inventory, @NotNull Player player) {
|
||||
return menu.createMenu(i, inventory, player);
|
||||
}
|
||||
};
|
||||
|
||||
player.openMenu(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<Integer, Inventory, FriendlyByteBuf, T> constructor) {
|
||||
return new ExtendedScreenHandlerType<>(constructor::apply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CraterCapabilityHandler capability) {
|
||||
if (entity instanceof ICraterCapProvider capProvider) {
|
||||
return capProvider.getCapability(capability, side);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CraterFluidHelper;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.systems.fluid.FabricFluidUtils;
|
||||
import com.hypherionmc.craterlib.systems.fluid.FluidTank;
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
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 CraterFluidHelper {
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
@@ -35,6 +35,10 @@ public class FabricNetworkHandler implements CraterNetworkHandler {
|
||||
this.modid = modid;
|
||||
}
|
||||
|
||||
public synchronized static CraterNetworkHandler of(String modId) {
|
||||
return NETWORK_HANDLERS.computeIfAbsent(modId, FabricNetworkHandler::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends CraterPacket<T>> void registerPacket(Class<T> clazz, Supplier<T> supplier, PacketDirection packetDirection) {
|
||||
ResourceLocation channelName = this.nextId();
|
||||
@@ -43,8 +47,10 @@ public class FabricNetworkHandler implements CraterNetworkHandler {
|
||||
final Function<FriendlyByteBuf, CraterPacket<?>> decoder = buf -> Util.make(supplier.get(), message -> message.read(buf));
|
||||
|
||||
switch (packetDirection) {
|
||||
case TO_CLIENT -> FabricNetworkHelper.getForDist(FabricLoader.getInstance().getEnvironmentType()).registerClientReceiver(channelName, decoder);
|
||||
case TO_SERVER -> FabricNetworkHelper.getForDist(FabricLoader.getInstance().getEnvironmentType()).registerServerReceiver(channelName, decoder);
|
||||
case TO_CLIENT ->
|
||||
FabricNetworkHelper.getForDist(FabricLoader.getInstance().getEnvironmentType()).registerClientReceiver(channelName, decoder);
|
||||
case TO_SERVER ->
|
||||
FabricNetworkHelper.getForDist(FabricLoader.getInstance().getEnvironmentType()).registerServerReceiver(channelName, decoder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +60,15 @@ public class FabricNetworkHandler implements CraterNetworkHandler {
|
||||
|
||||
@Override
|
||||
public Packet<?> toServerBound(CraterPacket<?> packet) {
|
||||
if (this.packets.get(packet.getClass()).direction() != PacketDirection.TO_SERVER) throw new IllegalStateException("Attempted sending message to wrong side, expected %s, was %s".formatted(PacketDirection.TO_SERVER, PacketDirection.TO_CLIENT));
|
||||
if (this.packets.get(packet.getClass()).direction() != PacketDirection.TO_SERVER)
|
||||
throw new IllegalStateException("Attempted sending message to wrong side, expected %s, was %s".formatted(PacketDirection.TO_SERVER, PacketDirection.TO_CLIENT));
|
||||
return this.toPacket(ClientPlayNetworking::createC2SPacket, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<?> toClientBound(CraterPacket<?> packet) {
|
||||
if (this.packets.get(packet.getClass()).direction() != PacketDirection.TO_CLIENT) throw new IllegalStateException("Attempted sending message to wrong side, expected %s, was %s".formatted(PacketDirection.TO_CLIENT, PacketDirection.TO_SERVER));
|
||||
if (this.packets.get(packet.getClass()).direction() != PacketDirection.TO_CLIENT)
|
||||
throw new IllegalStateException("Attempted sending message to wrong side, expected %s, was %s".formatted(PacketDirection.TO_CLIENT, PacketDirection.TO_SERVER));
|
||||
return this.toPacket(ServerPlayNetworking::createS2CPacket, packet);
|
||||
}
|
||||
|
||||
@@ -71,11 +79,8 @@ public class FabricNetworkHandler implements CraterNetworkHandler {
|
||||
return packetFactory.apply(identifier, byteBuf);
|
||||
}
|
||||
|
||||
public synchronized static CraterNetworkHandler of(String modId) {
|
||||
return NETWORK_HANDLERS.computeIfAbsent(modId, FabricNetworkHandler::new);
|
||||
}
|
||||
|
||||
private record PacketData(Class<? extends CraterPacket<?>> clazz, ResourceLocation identifier, PacketDirection direction) {
|
||||
private record PacketData(Class<? extends CraterPacket<?>> clazz, ResourceLocation identifier,
|
||||
PacketDirection direction) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -12,10 +12,6 @@ import java.util.function.Function;
|
||||
|
||||
public interface FabricNetworkHelper {
|
||||
|
||||
/* FABRIC ONLY */
|
||||
void registerClientReceiver(@NotNull ResourceLocation channelName, @NotNull Function<FriendlyByteBuf, @NotNull CraterPacket<?>> factory);
|
||||
void registerServerReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory);
|
||||
|
||||
public static FabricNetworkHelper getForDist(EnvType dist) {
|
||||
switch (dist) {
|
||||
case CLIENT -> {
|
||||
@@ -28,4 +24,9 @@ public interface FabricNetworkHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* FABRIC ONLY */
|
||||
void registerClientReceiver(@NotNull ResourceLocation channelName, @NotNull Function<FriendlyByteBuf, @NotNull CraterPacket<?>> factory);
|
||||
|
||||
void registerServerReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory);
|
||||
|
||||
}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
package com.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);
|
||||
}
|
||||
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
|
||||
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 java.util.Iterator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
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) {
|
||||
super((int) capacity, (p) -> validFluid.test(FluidVariant.of(p.getFluid())));
|
||||
}
|
||||
|
||||
public boolean isFluidValid(FluidVariant variant) {
|
||||
return isValidFluid(new FluidHolder(variant.getFluid(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) {
|
||||
StoragePreconditions.notBlankNotNegative(resource, maxAmount);
|
||||
return insert(new FluidHolder(resource.getFluid(), (int) maxAmount), FluidAction.EXECUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) {
|
||||
StoragePreconditions.notBlankNotNegative(resource, maxAmount);
|
||||
FluidHolder extracted = extract(new FluidHolder(resource.getFluid(), (int) maxAmount), FluidAction.EXECUTE);
|
||||
return extracted.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<StorageView<FluidVariant>> iterator() {
|
||||
// TODO: FIX THIS!
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResourceBlank() {
|
||||
return isTankEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidVariant getResource() {
|
||||
return FluidVariant.of(getFluidInTank().getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAmount() {
|
||||
return getTankLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return getTankCapacity();
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.common.FabricFluidHelper
|
@@ -30,7 +30,6 @@
|
||||
"${mod_id}.mixins.json",
|
||||
"${mod_id}.fabric.mixins.json"
|
||||
],
|
||||
"accessWidener": "${mod_id}.aw",
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.21",
|
||||
"fabric-api": "*",
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.client.CraterClientBus;
|
||||
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -16,7 +15,6 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
public class CraterLib {
|
||||
|
||||
public CraterLib() {
|
||||
CraterEventBus.INSTANCE.registerEventListener(CraterClientBus.class);
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeServerEvents());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
|
||||
}
|
||||
|
@@ -1,32 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.core.event.annot.CraterEventListener;
|
||||
import com.hypherionmc.craterlib.core.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
|
||||
public class CraterClientBus {
|
||||
|
||||
@CraterEventListener
|
||||
public static void lateInit(LateInitEvent event) {
|
||||
CraterConstants.LOG.info("Registering Creative Tabs");
|
||||
|
||||
CreativeTabRegistry.getTabs().forEach(tab -> {
|
||||
CreativeModeTab.Builder builder = CreativeModeTab.builder();
|
||||
builder.title(Component.translatable("itemGroup." + tab.getResourceLocation().toString().replace(":", ".")));
|
||||
builder.icon(tab.getIcon());
|
||||
|
||||
if (!tab.getBackgroundSuffix().isEmpty()) {
|
||||
builder.backgroundSuffix(tab.getBackgroundSuffix());
|
||||
}
|
||||
|
||||
CreativeModeTab tabb = Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, tab.getResourceKey(), builder.build());
|
||||
tab.setTab(tabb);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,19 +1,10 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.common.item.BlockItemDyable;
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.util.ColorPropertyFunction;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.Objects;
|
||||
|
||||
@@ -23,23 +14,8 @@ import java.util.Objects;
|
||||
*/
|
||||
public class ForgeClientHelper implements ClientPlatform {
|
||||
|
||||
public ForgeClientHelper() {}
|
||||
|
||||
@Override
|
||||
public void registerItemProperty(BlockItemDyable item, String property) {
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
ItemProperties.register(item, new ResourceLocation(property), new ColorPropertyFunction(item));
|
||||
public ForgeClientHelper() {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void registerCustomRenderTypes(Collection<RegistryObject<Block>> blocks) {
|
||||
blocks.forEach(blk -> {
|
||||
if (blk.get() instanceof CustomRenderType type) {
|
||||
ItemBlockRenderTypes.setRenderLayer(blk.get(), type.getCustomRenderType());
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public Minecraft getClientInstance() {
|
||||
@@ -61,9 +37,4 @@ public class ForgeClientHelper implements ClientPlatform {
|
||||
Objects.requireNonNull(Minecraft.getInstance().getConnection(), "Cannot send packets when not in game!");
|
||||
return Minecraft.getInstance().getConnection().getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockEntityRenderer(BlockEntityType<? extends BlockEntity> blockEntityType, BlockEntityRendererProvider blockEntityRendererFactory) {
|
||||
BlockEntityRenderers.register(blockEntityType, blockEntityRendererFactory);
|
||||
}
|
||||
}
|
||||
|
@@ -1,101 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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.function.Supplier;
|
||||
|
||||
/** Copied from <a href="https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.18.x/enderio-machines/src/main/java/com/enderio/machines/client/FluidStackWidget.java">...</a>*/
|
||||
public class FluidStackWidget extends AbstractWidget {
|
||||
|
||||
private final Screen displayOn;
|
||||
private final Supplier<FluidTank> getFluid;
|
||||
|
||||
private final String toolTipTitle;
|
||||
|
||||
public FluidStackWidget(Screen displayOn, Supplier<FluidTank> getFluid, int pX, int pY, int pWidth, int pHeight, String toolTipTitle) {
|
||||
super(pX, pY, pWidth, pHeight, Component.empty());
|
||||
this.displayOn = displayOn;
|
||||
this.getFluid = getFluid;
|
||||
this.toolTipTitle = toolTipTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(@NotNull GuiGraphics pPoseStack, int pMouseX, int pMouseY, float pPartialTicks) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
FluidTank fluidTank = getFluid.get();
|
||||
if (!fluidTank.isEmpty()) {
|
||||
FluidStack fluidStack = fluidTank.getFluid();
|
||||
IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluidStack.getFluid());
|
||||
ResourceLocation still = props.getStillTexture(fluidStack);
|
||||
if (still != null) {
|
||||
AbstractTexture texture = minecraft.getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS);
|
||||
if (texture instanceof TextureAtlas atlas) {
|
||||
TextureAtlasSprite sprite = atlas.getSprite(still);
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
||||
|
||||
int color = props.getTintColor();
|
||||
RenderSystem.setShaderColor(
|
||||
FastColor.ARGB32.red(color) / 255.0F,
|
||||
FastColor.ARGB32.green(color) / 255.0F,
|
||||
FastColor.ARGB32.blue(color) / 255.0F,
|
||||
FastColor.ARGB32.alpha(color) / 255.0F);
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
int stored = fluidTank.getFluidAmount();
|
||||
float capacity = fluidTank.getCapacity();
|
||||
float filledVolume = stored / capacity;
|
||||
int renderableHeight = (int)(filledVolume * height);
|
||||
|
||||
int atlasWidth = (int)(sprite.getY() / (sprite.getU1() - sprite.getU0()));
|
||||
int atlasHeight = (int)(sprite.getY() / (sprite.getV1() - sprite.getV0()));
|
||||
|
||||
pPoseStack.pose().pushPose();
|
||||
pPoseStack.pose().translate(0, height-16, 0);
|
||||
for (int i = 0; i < Math.ceil(renderableHeight / 16f); i++) {
|
||||
int drawingHeight = Math.min(16, renderableHeight - 16*i);
|
||||
int notDrawingHeight = 16 - drawingHeight;
|
||||
// TODO Double Check this
|
||||
pPoseStack.blit(TextureAtlas.LOCATION_BLOCKS, getX(), getY() + notDrawingHeight, 0, sprite.getU0()*atlasWidth, sprite.getV0()*atlasHeight + notDrawingHeight, this.width, drawingHeight, atlasWidth, atlasHeight);
|
||||
pPoseStack.pose().translate(0,-16, 0);
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
pPoseStack.pose().popPose();
|
||||
}
|
||||
}
|
||||
//renderToolTip(pPoseStack, pMouseX, pMouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateWidgetNarration(NarrationElementOutput p_259858_) {
|
||||
|
||||
}
|
||||
|
||||
// TODO Fix Tooltips
|
||||
/*@Override
|
||||
public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
|
||||
if (isActive() && isHovered) {
|
||||
displayOn.renderTooltip(pPoseStack, Arrays.asList(LangUtils.getTooltipTitle(toolTipTitle).getVisualOrderText(), Component.literal((int) (((float)this.getFluid.get().getFluidAmount() / this.getFluid.get().getCapacity()) * 100) + "%").getVisualOrderText()), pMouseX, pMouseY);
|
||||
}
|
||||
}*/
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.core.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = CraterConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class ForgeCommonEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTabs(BuildCreativeModeTabContentsEvent event) {
|
||||
CreativeModeTab tab = event.getTab();
|
||||
|
||||
CreativeTabRegistry.getTabItems().stream()
|
||||
.filter(p -> p.getLeft().get() == tab && p.getRight() != null)
|
||||
.forEach(itemPair -> event.accept(itemPair.getRight()));
|
||||
}
|
||||
}
|
@@ -1,35 +1,15 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.ICraterCapProvider;
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.network.ForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.systems.energy.ForgeEnergyReader;
|
||||
import com.hypherionmc.craterlib.systems.fluid.ForgeFluidReader;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -38,7 +18,8 @@ public class ForgeCommonHelper implements CommonPlatform {
|
||||
|
||||
public static Map<ResourceLocation, CreativeModeTab> TABS = new HashMap<>();
|
||||
|
||||
public ForgeCommonHelper() {}
|
||||
public ForgeCommonHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraterNetworkHandler createPacketHandler(String modid, boolean requiredClient, boolean requiredServer) {
|
||||
@@ -49,41 +30,4 @@ public class ForgeCommonHelper implements CommonPlatform {
|
||||
public MinecraftServer getMCServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openMenu(ServerPlayer player, MenuProvider menu, @Nullable Consumer<FriendlyByteBuf> initialData) {
|
||||
if (initialData != null) {
|
||||
player.openMenu(menu, initialData);
|
||||
} else {
|
||||
player.openMenu(menu, player.getOnPos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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, CraterCapabilityHandler capability) {
|
||||
if (capability == CraterCapabilityHandler.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 == CraterCapabilityHandler.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();
|
||||
}
|
||||
}
|
||||
|
@@ -1,58 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CraterFluidHelper;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.systems.fluid.ForgeFluidTankInteractor;
|
||||
import com.hypherionmc.craterlib.systems.fluid.ForgeFluidUtils;
|
||||
import com.hypherionmc.craterlib.systems.fluid.ForgeWrappedFluidTank;
|
||||
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 CraterFluidHelper {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
@@ -15,7 +15,8 @@ import java.io.File;
|
||||
*/
|
||||
public class ForgeLoaderHelper implements ModloaderEnvironment {
|
||||
|
||||
public ForgeLoaderHelper() {}
|
||||
public ForgeLoaderHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFabric() {
|
||||
|
@@ -1,57 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.ICraterCapProvider;
|
||||
import com.hypherionmc.craterlib.common.blockentity.CraterBlockEntity;
|
||||
import com.hypherionmc.craterlib.core.systems.energy.CustomEnergyStorage;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.core.systems.inventory.SimpleInventory;
|
||||
import com.hypherionmc.craterlib.systems.energy.ForgeEnergyWrapper;
|
||||
import com.hypherionmc.craterlib.systems.fluid.ForgeWrappedFluidTank;
|
||||
import com.hypherionmc.craterlib.systems.inventory.ForgeInventoryWrapper;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Mixin(CraterBlockEntity.class)
|
||||
public class BlockEntityMixin implements ICapabilityProvider {
|
||||
|
||||
@Override
|
||||
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||
ICraterCapProvider capProvider = (ICraterCapProvider) this;
|
||||
|
||||
if (cap == ForgeCapabilities.ENERGY) {
|
||||
Optional<CustomEnergyStorage> forgeCap = capProvider.getCapability(CraterCapabilityHandler.ENERGY, side);
|
||||
if (forgeCap.isPresent()) {
|
||||
return LazyOptional.of(() -> new ForgeEnergyWrapper(forgeCap.get())).cast();
|
||||
}
|
||||
}
|
||||
|
||||
if (cap == ForgeCapabilities.ITEM_HANDLER) {
|
||||
Optional<SimpleInventory> inventory = capProvider.getCapability(CraterCapabilityHandler.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(CraterCapabilityHandler.FLUID, side);
|
||||
if (fluidTank.isPresent()) {
|
||||
return LazyOptional.of(() -> (ForgeWrappedFluidTank)fluidTank.get()).cast();
|
||||
}
|
||||
}
|
||||
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ public class ConfigScreenHandlerMixin {
|
||||
|
||||
/**
|
||||
* Inject Auto Generated config Screens into forge
|
||||
*
|
||||
* @param selectedMod
|
||||
* @param cir
|
||||
*/
|
||||
|
@@ -49,6 +49,29 @@ public class ForgeNetworkHandler implements CraterNetworkHandler {
|
||||
this.serverRequired = serverRequired;
|
||||
}
|
||||
|
||||
public synchronized static CraterNetworkHandler of(String modId, boolean clientRequired, boolean serverRequired) {
|
||||
ForgeNetworkHandler handler = NETWORK_HANDLERS.computeIfAbsent(modId, modId1 -> new ForgeNetworkHandler(buildSimpleChannel(modId1, clientRequired, serverRequired), clientRequired, serverRequired));
|
||||
if (handler.clientRequired != clientRequired)
|
||||
throw new IllegalArgumentException("client channel settings mismatch, expected %s, but was %s".formatted(handler.clientRequired, clientRequired));
|
||||
if (handler.serverRequired != serverRequired)
|
||||
throw new IllegalArgumentException("server channel settings mismatch, expected %s, but was %s".formatted(handler.serverRequired, serverRequired));
|
||||
return handler;
|
||||
}
|
||||
|
||||
private static SimpleChannel buildSimpleChannel(String modId, boolean clientAcceptsVanillaOrMissing, boolean serverAcceptsVanillaOrMissing) {
|
||||
ChannelBuilder builder = ChannelBuilder.named(new ResourceLocation(modId, "crater_network"));
|
||||
|
||||
if (clientAcceptsVanillaOrMissing) {
|
||||
builder = builder.optionalClient();
|
||||
}
|
||||
|
||||
if (serverAcceptsVanillaOrMissing) {
|
||||
builder = builder.optionalServer();
|
||||
}
|
||||
|
||||
return builder.simpleChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends CraterPacket<T>> void registerPacket(Class<T> clazz, Supplier<T> supplier, PacketDirection packetDirection) {
|
||||
BiConsumer<T, FriendlyByteBuf> encoder = CraterPacket::write;
|
||||
@@ -106,27 +129,6 @@ public class ForgeNetworkHandler implements CraterNetworkHandler {
|
||||
CraterNetworkHandler.super.sendToServer(packet);
|
||||
}
|
||||
|
||||
public synchronized static CraterNetworkHandler of(String modId, boolean clientRequired, boolean serverRequired) {
|
||||
ForgeNetworkHandler handler = NETWORK_HANDLERS.computeIfAbsent(modId, modId1 -> new ForgeNetworkHandler(buildSimpleChannel(modId1, clientRequired, serverRequired), clientRequired, serverRequired));
|
||||
if (handler.clientRequired != clientRequired) throw new IllegalArgumentException("client channel settings mismatch, expected %s, but was %s".formatted(handler.clientRequired, clientRequired));
|
||||
if (handler.serverRequired != serverRequired) throw new IllegalArgumentException("server channel settings mismatch, expected %s, but was %s".formatted(handler.serverRequired, serverRequired));
|
||||
return handler;
|
||||
}
|
||||
|
||||
private static SimpleChannel buildSimpleChannel(String modId, boolean clientAcceptsVanillaOrMissing, boolean serverAcceptsVanillaOrMissing) {
|
||||
ChannelBuilder builder = ChannelBuilder.named(new ResourceLocation(modId, "crater_network"));
|
||||
|
||||
if (clientAcceptsVanillaOrMissing) {
|
||||
builder = builder.optionalClient();
|
||||
}
|
||||
|
||||
if (serverAcceptsVanillaOrMissing) {
|
||||
builder = builder.optionalServer();
|
||||
}
|
||||
|
||||
return builder.simpleChannel();
|
||||
}
|
||||
|
||||
private LogicalSide getSideFromDirection(PacketDirection direction) {
|
||||
return direction == PacketDirection.TO_CLIENT ? LogicalSide.CLIENT : LogicalSide.SERVER;
|
||||
}
|
||||
|
@@ -1,37 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.energy;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.energy.ICraterEnergyStorage;
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.energy;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.energy.CustomEnergyStorage;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Forge Energy Support on top of the custom system
|
||||
*/
|
||||
public record ForgeEnergyWrapper(CustomEnergyStorage storage) implements IEnergyStorage {
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return storage.getPowerLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return storage.getPowerCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return storage.getMaxOutput() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return storage.getMaxInput() > 0;
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
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());
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package com.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;
|
||||
}
|
||||
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.fluid;
|
||||
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
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,90 +0,0 @@
|
||||
package com.hypherionmc.craterlib.systems.inventory;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.hypherionmc.craterlib.core.systems.inventory.SimpleInventory;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class ForgeInventoryWrapper implements WorldlyContainer {
|
||||
|
||||
private final SimpleInventory inventory;
|
||||
private final Supplier<int[]> slots = Suppliers.memoize(() -> IntStream.range(0, getContainerSize()).toArray());
|
||||
|
||||
public ForgeInventoryWrapper(SimpleInventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace(Direction side) {
|
||||
return slots.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceItemThroughFace(int slot, ItemStack stack, @Nullable Direction side) {
|
||||
if (canPlaceItem(slot, stack)) {
|
||||
ItemStack existing = getItem(slot);
|
||||
return existing.getCount() < getMaxStackSize();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return inventory.getItemHandler().getContainerSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return inventory.getItemHandler().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
return inventory.getItemHandler().getItem(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int p_18942_, int p_18943_) {
|
||||
return inventory.getItemHandler().removeItem(p_18942_, p_18943_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
return inventory.getItemHandler().removeItemNoUpdate(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
inventory.getItemHandler().setItem(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
inventory.getItemHandler().setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return inventory.getItemHandler().stillValid(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
inventory.getItemHandler().clearContent();
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
public net.minecraft.client.renderer.LevelRenderer$RenderChunkInfo
|
@@ -1,13 +1,13 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[49,)"
|
||||
license = "MIT"
|
||||
issueTrackerURL="https://github.com/firstdarkdev/craterLib/issues"
|
||||
issueTrackerURL = "https://github.com/firstdarkdev/craterLib/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "${mod_id}"
|
||||
version = "${version}"
|
||||
displayName = "${mod_name}"
|
||||
displayURL="https://modrinth.com/mod/craterlib"
|
||||
displayURL = "https://modrinth.com/mod/craterlib"
|
||||
logoFile = "craterlib_logo.png"
|
||||
#credits="Thanks for this example mod goes to Java"
|
||||
authors = "${mod_author}, Zenith"
|
||||
@@ -16,14 +16,14 @@ A library mod used by First Dark Development and HypherionSA Mods
|
||||
'''
|
||||
displayTest = "MATCH_VERSION"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[49,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.20.3,1.21)"
|
||||
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.common.ForgeFluidHelper
|
@@ -4,7 +4,6 @@
|
||||
"package": "com.hypherionmc.craterlib.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"BlockEntityMixin"
|
||||
],
|
||||
"client": [
|
||||
"ConfigScreenHandlerMixin"
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.client.CraterClientBus;
|
||||
import com.hypherionmc.craterlib.common.NeoForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -16,7 +15,6 @@ import net.neoforged.neoforge.common.NeoForge;
|
||||
public class CraterLib {
|
||||
|
||||
public CraterLib(IEventBus eventBus) {
|
||||
CraterEventBus.INSTANCE.registerEventListener(CraterClientBus.class);
|
||||
NeoForge.EVENT_BUS.register(new NeoForgeServerEvents());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user