[CHORE] Cleanup API's that's unused by any mod currently

This commit is contained in:
2024-01-01 21:42:14 +02:00
parent 8aa8c3b62c
commit 8b4172cfef
125 changed files with 194 additions and 3355 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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
}

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -5,15 +5,15 @@ import com.mojang.realmsclient.dto.RealmsServer;
public class PlayerJoinRealmEvent extends CraterEvent {
private final RealmsServer server;
private final RealmsServer server;
public PlayerJoinRealmEvent(RealmsServer server) {
this.server = server;
}
public PlayerJoinRealmEvent(RealmsServer server) {
this.server = server;
}
public RealmsServer getServer() {
return server;
}
public RealmsServer getServer() {
return server;
}
@Override
public boolean canCancel() {

View File

@@ -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;
}

View File

@@ -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() {
}
}
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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> {

View File

@@ -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

View File

@@ -54,7 +54,8 @@ public abstract class Option<T> extends AbstractContainerEventHandler {
return listener;
}
public void onAdd() {}
public void onAdd() {
}
protected void reset() {
onAdd();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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() {

View File

@@ -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) {
@@ -39,11 +38,11 @@ public final class CraterEventBus {
private void registerListenerMethods(List<EventMethod> methods) {
for (EventMethod m : methods) {
Consumer<CraterEvent> listener = (event) -> {
try {
m.method.invoke(m.parentObject, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
m.method.invoke(m.parentObject, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
ListenerContainer container = new ListenerContainer(m.eventType, listener, m.priority);
@@ -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) {

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -15,10 +15,11 @@ 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
* @param steamId Steam ID of the game
* @param handlers Optional Event Callback Handlers
* @param autoRegister Auto Register the running game
* @param steamId Steam ID of the game
*/
void Discord_Initialize(@NotNull String applicationId, @Nullable DiscordEventHandlers handlers, boolean autoRegister, @Nullable String steamId);
@@ -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,13 +53,15 @@ 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}
* @param reply Reply to the request. See {@link DiscordReply}
*/
void Discord_Respond(@NotNull String userid, int reply);
/**
* Replace the already registered {@link DiscordEventHandlers}
*
* @param handlers The new handlers to apply
*/
void Discord_UpdateHandlers(@Nullable DiscordEventHandlers handlers);
@@ -65,17 +69,19 @@ 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
*
* NB: THIS DOES NOT WORK WITH MINECRAFT
* @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
* @param steamId The Steam ID of the application/game
*/
void Discord_RegisterSteamGame(String applicationId, String steamId);

View File

@@ -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;

View File

@@ -30,10 +30,10 @@ public class DiscordUser extends Structure {
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(
"userId",
"username",
"discriminator",
"avatar"
"userId",
"username",
"discriminator",
"avatar"
);
}
}

View File

@@ -10,8 +10,9 @@ public interface DisconnectedCallback extends Callback {
/**
* Called when RPC disconnected
*
* @param errorCode Error code if any
* @param message Details about the disconnection
* @param message Details about the disconnection
*/
void apply(int errorCode, String message);
}

View File

@@ -10,8 +10,9 @@ public interface ErroredCallback extends Callback {
/**
* Called when an RPC error occurs
*
* @param errorCode Error code if any
* @param message Details about the error
* @param message Details about the error
*/
void apply(int errorCode, String message);
}

View File

@@ -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);

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -24,8 +24,9 @@ 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
* @param url The URL the button will open when clicked
* @return The constructed button
*/
public static RPCButton create(@NotNull String label, @NotNull String url) {

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -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());
}
}

View File

@@ -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) {};
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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"))

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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")));
}
}

View File

@@ -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();
}
}

View File

@@ -12,6 +12,7 @@ public class ServiceUtil {
/**
* Try to load a service
*
* @param clazz The service class type to load
* @return The loaded class
*/

View File

@@ -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

View File

@@ -6,8 +6,6 @@
"mixins": [
],
"client": [
"colors.BlockColorsMixin",
"colors.ItemColorsMixin",
"events.PlayerMixin",
"events.client.ClientLevelMixin",
"events.client.MinecraftMixin",