Merge branch '1.18' into recipe_serde

# Conflicts:
#	RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java
#	src/datagen/groovy/techreborn/datagen/recipes/smelting/SmeltingRecipesProvider.groovy
This commit is contained in:
modmuss50 2022-01-20 18:51:48 +00:00
commit 8863ea30b3
454 changed files with 3884 additions and 1302 deletions

View file

@ -27,21 +27,23 @@ package reborncore;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import reborncore.api.ToolManager;
import reborncore.api.blockentity.UnloadHandler;
import reborncore.common.RebornCoreCommands;
import reborncore.common.RebornCoreConfig;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.chunkloading.ChunkLoaderManager;
import reborncore.common.config.Configuration;
import reborncore.common.crafting.ingredient.IngredientManager;
import reborncore.common.fluid.RebornFluidManager;
import reborncore.common.misc.ModSounds;
import reborncore.common.misc.RebornCoreTags;
import reborncore.common.multiblock.MultiblockRegistry;
@ -63,7 +65,7 @@ public class RebornCore implements ModInitializer {
public static final String MOD_VERSION = "@MODVERSION@";
public static final String WEB_URL = "https://files.modmuss50.me/";
public static final Logger LOGGER = LogManager.getFormatterLogger(MOD_ID);
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static File configDir;
public static boolean LOADED = false;
@ -107,7 +109,6 @@ public class RebornCore implements ModInitializer {
ServerBoundPackets.init();
IngredientManager.setup();
RebornFluidManager.setupBucketMap();
RebornCoreCommands.setup();
@ -119,6 +120,9 @@ public class RebornCore implements ModInitializer {
if (blockEntity instanceof UnloadHandler) ((UnloadHandler) blockEntity).onUnload();
});
ServerWorldEvents.LOAD.register((server, world) -> ChunkLoaderManager.get(world).onServerWorldLoad(world));
ServerTickEvents.START_WORLD_TICK.register(world -> ChunkLoaderManager.get(world).onServerWorldTick(world));
FluidStorage.SIDED.registerFallback((world, pos, state, be, direction) -> {
if (be instanceof MachineBaseBlockEntity machineBase) {
return machineBase.getTank();

View file

@ -26,10 +26,9 @@ package reborncore.client.gui.builder.widget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import org.apache.logging.log4j.util.TriConsumer;
import reborncore.common.misc.TriConsumer;
public class GuiButtonExtended extends GuiButtonSimple {
public class GuiButtonExtended extends ButtonWidget {
private TriConsumer<GuiButtonExtended, Double, Double> clickHandler;
@ -51,6 +50,6 @@ public class GuiButtonExtended extends GuiButtonSimple {
if (clickHandler != null) {
clickHandler.accept(this, mouseX, mouseY);
}
super.onClick(mouseY, mouseY);
super.onClick(mouseX, mouseY);
}
}

View file

@ -28,10 +28,19 @@ import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
public class GuiButtonSimple extends ButtonWidget {
/**
* @deprecated Please use {@link ButtonWidget}
*/
@Deprecated
public GuiButtonSimple(int x, int y, Text buttonText, ButtonWidget.PressAction pressAction) {
super(x, y, 20, 200, buttonText, pressAction);
}
/**
* @deprecated Please use {@link ButtonWidget}
*/
@Deprecated
public GuiButtonSimple(int x, int y, int widthIn, int heightIn, Text buttonText, ButtonWidget.PressAction pressAction) {
super(x, y, widthIn, heightIn, buttonText, pressAction);
}

View file

@ -26,7 +26,6 @@ package reborncore.client.gui.guibuilder;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
@ -52,12 +51,11 @@ import reborncore.api.IListInfoProvider;
import reborncore.client.RenderUtil;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.slot.GuiTab;
import reborncore.common.fluid.FluidUtil;
import reborncore.common.fluid.FluidUtils;
import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.PowerSystem.EnergySystem;
import reborncore.common.util.FluidTextHelper;
import reborncore.common.util.StringUtils;
import java.util.ArrayList;
@ -682,7 +680,7 @@ public class GuiBuilder {
new LiteralText(String.format("%s / %s", amount, maxCapacity))
.formatted(Formatting.GOLD)
.append(SPACE_TEXT)
.append(FluidUtil.getFluidName(fluid))
.append(FluidUtils.getFluidName(fluid))
);
}

View file

@ -26,9 +26,6 @@ package reborncore.client.screen.builder;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.inventory.CraftingInventory;
@ -49,7 +46,7 @@ import reborncore.client.gui.slots.SlotOutput;
import reborncore.client.screen.builder.slot.FilteredSlot;
import reborncore.client.screen.builder.slot.UpgradeSlot;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.container.ItemFluidInfo;
import reborncore.common.fluid.FluidUtils;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.api.EnergyStorageUtil;
@ -114,8 +111,7 @@ public class BlockEntityScreenHandlerBuilder {
}
public BlockEntityScreenHandlerBuilder fluidSlot(final int index, final int x, final int y) {
this.parent.slots.add(new FilteredSlot(this.inventory, index, x, y).setFilter(
stack -> stack.getItem() instanceof ItemFluidInfo));
this.parent.slots.add(new FilteredSlot(this.inventory, index, x, y).setFilter(FluidUtils::isContainer));
return this;
}

View file

@ -37,8 +37,8 @@ import net.minecraft.screen.slot.Slot;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.network.ClientBoundPackets;
import reborncore.common.network.NetworkManager;
@ -54,7 +54,7 @@ import java.util.function.Predicate;
import java.util.function.Supplier;
public class BuiltScreenHandler extends ScreenHandler {
private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(BuiltScreenHandler.class);
private final String name;

View file

@ -28,15 +28,12 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
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.StorageUtil;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.common.fluid.FluidUtil;
import reborncore.common.util.NBTSerializable;
import reborncore.common.util.Tank;
import java.util.ArrayList;
import java.util.Arrays;

View file

@ -56,7 +56,7 @@ import reborncore.api.blockentity.IUpgrade;
import reborncore.api.blockentity.IUpgradeable;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.FluidUtil;
import reborncore.common.fluid.FluidUtils;
import reborncore.common.util.ItemHandlerUtils;
import reborncore.common.util.Tank;
import reborncore.common.util.WrenchUtils;
@ -187,7 +187,7 @@ public abstract class BlockMachineBase extends BaseBlockEntityProvider implement
if (blockEntity instanceof MachineBaseBlockEntity) {
Tank tank = ((MachineBaseBlockEntity) blockEntity).getTank();
if (tank != null && FluidUtil.interactWithFluidHandler(playerIn, hand, tank)) {
if (tank != null && FluidUtils.interactWithFluidHandler(playerIn, hand, tank)) {
return ActionResult.SUCCESS;
}
}

View file

@ -27,6 +27,7 @@ package reborncore.common.chunkloading;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicketType;
@ -70,7 +71,7 @@ public class ChunkLoaderManager extends PersistentState {
chunkLoaderManager.loadedChunks.clear();
List<LoadedChunk> chunks = CODEC.parse(NbtOps.INSTANCE, tag.getCompound("loadedchunks"))
List<LoadedChunk> chunks = CODEC.parse(NbtOps.INSTANCE, tag.getList("loadedchunks", NbtElement.COMPOUND_TYPE))
.result()
.orElse(Collections.emptyList());
@ -123,8 +124,7 @@ public class ChunkLoaderManager extends PersistentState {
LoadedChunk loadedChunk = new LoadedChunk(chunkPos, getWorldName(world), player, chunkLoader);
loadedChunks.add(loadedChunk);
final ServerChunkManager serverChunkManager = ((ServerWorld) world).getChunkManager();
serverChunkManager.addTicket(ChunkLoaderManager.CHUNK_LOADER, loadedChunk.getChunk(), RADIUS, loadedChunk.getChunk());
loadChunk((ServerWorld) world, loadedChunk);
markDirty();
}
@ -148,6 +148,16 @@ public class ChunkLoaderManager extends PersistentState {
markDirty();
}
public void onServerWorldLoad(ServerWorld world) {
loadedChunks.forEach(loadedChunk -> loadChunk(world, loadedChunk));
}
public void onServerWorldTick(ServerWorld world) {
if (!loadedChunks.isEmpty()) {
world.resetIdleTimeout();
}
}
public static Identifier getWorldName(World world){
return world.getRegistryKey().getValue();
}
@ -172,6 +182,11 @@ public class ChunkLoaderManager extends PersistentState {
NetworkManager.sendToPlayer(ClientBoundPackets.createPacketSyncLoadedChunks(chunks), serverPlayerEntity);
}
private void loadChunk(ServerWorld world, LoadedChunk loadedChunk) {
ChunkPos chunkPos = loadedChunk.getChunk();
world.getChunkManager().addTicket(ChunkLoaderManager.CHUNK_LOADER, chunkPos, RADIUS, chunkPos);
}
public static class LoadedChunk {
public static Codec<ChunkPos> CHUNK_POS_CODEC = RecordCodecBuilder.create(instance ->

View file

@ -1,140 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.crafting;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import org.apache.commons.lang3.Validate;
import java.util.HashMap;
import java.util.function.Function;
public final class ConditionManager {
private static final HashMap<Identifier, RecipeCondition<?>> RECIPE_CONDITIONS = new HashMap<>();
private static final HashMap<Identifier, Class<?>> RECIPE_CONDITION_TYPES = new HashMap<>();
static {
//Only loads the recipe in a development env
register("development", Boolean.class, (bool) -> bool == FabricLoader.getInstance().isDevelopmentEnvironment());
//Only loads the recipe when the item is registered
register("item", Identifier.class, (id) -> registryContains(Registry.ITEM, id));
//Only loads the recipe when the fluid is registered
register("fluid", Identifier.class, (id) -> registryContains(Registry.FLUID, id));
//Only loads the recipe when the tag is loaded
register("tag", Identifier.class, s -> ItemTags.getTagGroup().getTags().containsKey(s));
//Only load the recipe if the provided mod is loaded
register("mod", String.class, s -> FabricLoader.getInstance().isModLoaded(s));
//Never load, just pass whatever in as the string
register("never", String.class, s -> false);
}
private static boolean registryContains(SimpleRegistry<?> registry, Identifier ident) {
return registry.containsId(ident);
}
public static <T> void register(String name, Class<T> type, RecipeCondition<T> recipeCondition){
register(new Identifier("reborncore", name), type, recipeCondition);
}
public static <T> void register(Identifier identifier, Class<T> type, RecipeCondition<T> recipeCondition){
Validate.isTrue(!RECIPE_CONDITIONS.containsKey(identifier), "Recipe condition already registered");
RECIPE_CONDITIONS.put(identifier, recipeCondition);
RECIPE_CONDITION_TYPES.put(identifier, type);
}
public static RecipeCondition<?> getRecipeCondition(Identifier identifier){
RecipeCondition<?> condition = RECIPE_CONDITIONS.get(identifier);
if(condition == null){
throw new UnsupportedOperationException("Could not find recipe condition for " + identifier.toString());
}
return condition;
}
public static boolean shouldLoadRecipe(JsonObject jsonObject){
if(!jsonObject.has("conditions")) return true;
return jsonObject.get("conditions").getAsJsonObject().entrySet().stream()
.allMatch(entry -> shouldLoad(entry.getKey(), entry.getValue()));
}
public static boolean shouldLoad(String ident, JsonElement jsonElement){
Identifier identifier = parseIdent(ident);
RecipeCondition<?> recipeCondition = getRecipeCondition(identifier);
Class<?> type = RECIPE_CONDITION_TYPES.get(identifier);
return shouldLoad(type, jsonElement, recipeCondition);
}
@SuppressWarnings("unchecked")
private static boolean shouldLoad(Class type, JsonElement jsonElement, RecipeCondition recipeCondition){
Object val = TypeHelper.getValue(type, jsonElement);
return recipeCondition.shouldLoad(val);
}
private static Identifier parseIdent(String string) {
if(string.contains(":")){
return new Identifier(string);
}
return new Identifier("reborncore", string);
}
@FunctionalInterface
public interface RecipeCondition<T> {
boolean shouldLoad(T t);
}
private static class TypeHelper {
private static final HashMap<Class<?>, Function<JsonElement, ?>> FUNCTIONS = new HashMap<>();
static {
register(String.class, JsonElement::getAsString);
register(Boolean.class, JsonElement::getAsBoolean);
register(Identifier.class, element -> new Identifier(element.getAsString()));
}
private static <T> void register(Class<T> type, Function<JsonElement, T> function){
Validate.isTrue(!FUNCTIONS.containsKey(type), "Function for this class is already registered");
FUNCTIONS.put(type, function);
}
public static <T> T getValue(Class<T> type, JsonElement jsonElement){
Validate.isTrue(FUNCTIONS.containsKey(type), "Function for this class could not be found");
//noinspection unchecked
return (T) FUNCTIONS.get(type).apply(jsonElement);
}
}
}

View file

@ -52,10 +52,6 @@ public record RebornRecipeType<R extends RebornRecipe>(
try {
R recipe = newRecipe(json, recipeId);
if (!ConditionManager.shouldLoadRecipe(json)) {
return recipeSerde.createDummy(this, recipeId);
}
return recipe;
} catch (Throwable t) {
RebornCore.LOGGER.error("Failed to read recipe: " + recipeId, t);

View file

@ -1,64 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.fluid;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.util.Tank;
public class FluidUtil {
@Deprecated
public static FluidInstance getFluidHandler(ItemStack stack) {
return null;
}
@Deprecated
public static boolean interactWithFluidHandler(PlayerEntity playerIn, Hand hand, Tank tank) {
return false;
}
@Deprecated
public static ItemStack getFilledBucket(FluidInstance stack) {
return null;
}
public static String getFluidName(@NotNull FluidInstance fluidInstance) {
// TODO: use FluidVariantRendering
return getFluidName(fluidInstance.getFluid());
}
public static String getFluidName(@NotNull Fluid fluid) {
return StringUtils.capitalize(Registry.FLUID.getId(fluid).getPath());
}
}

View file

@ -0,0 +1,188 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.fluid;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil;
import net.fabricmc.fabric.api.transfer.v1.storage.base.FilteringStorage;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.util.Tank;
import reborncore.mixin.common.AccessorFluidBlock;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class FluidUtils {
@NotNull
public static Fluid fluidFromBlock(Block block) {
if (block instanceof AccessorFluidBlock) {
return ((AccessorFluidBlock) block).getFluid();
}
return Fluids.EMPTY;
}
public static List<Fluid> getAllFluids() {
return Registry.FLUID.stream().collect(Collectors.toList());
}
public static boolean drainContainers(Tank tank, Inventory inventory, int inputSlot, int outputSlot) {
return drainContainers(tank, inventory, inputSlot, outputSlot, false);
}
public static boolean drainContainers(Tank tank, Inventory inventory, int inputSlot, int outputSlot, boolean voidFluid) {
Storage<FluidVariant> itemStorage = getItemFluidStorage(inventory, inputSlot, outputSlot);
if (voidFluid) {
// Just extract as much as we can
try (Transaction tx = Transaction.openOuter()) {
boolean didSomething = false;
for (var view : itemStorage.iterable(tx)) {
if (view.isResourceBlank()) continue;
didSomething = didSomething | view.extract(view.getResource(), Long.MAX_VALUE, tx) > 0;
}
tx.commit();
return didSomething;
}
} else {
return StorageUtil.move(itemStorage, tank, fv -> true, Long.MAX_VALUE, null) > 0;
}
}
public static boolean fillContainers(Tank source, Inventory inventory, int inputSlot, int outputSlot) {
return StorageUtil.move(
source,
getItemFluidStorage(inventory, inputSlot, outputSlot),
fv -> true,
Long.MAX_VALUE,
null
) > 0;
}
private static Storage<FluidVariant> getItemFluidStorage(Inventory inventory, int inputSlot, int outputSlot) {
var invWrapper = InventoryStorage.of(inventory, null);
var input = invWrapper.getSlot(inputSlot);
var output = invWrapper.getSlot(outputSlot);
var context = new ContainerItemContext() {
@Override
public SingleSlotStorage<ItemVariant> getMainSlot() {
return input;
}
@Override
public long insertOverflow(ItemVariant itemVariant, long maxAmount, TransactionContext transactionContext) {
return output.insert(itemVariant, maxAmount, transactionContext);
}
@Override
public long insert(ItemVariant itemVariant, long maxAmount, TransactionContext transaction) {
// Don't allow insertion in the input slot
return insertOverflow(itemVariant, maxAmount, transaction);
}
@Override
public List<SingleSlotStorage<ItemVariant>> getAdditionalSlots() {
return List.of();
}
};
var storage = context.find(FluidStorage.ITEM);
return storage != null ? storage : Storage.empty();
}
public static boolean fluidEquals(@NotNull Fluid fluid, @NotNull Fluid fluid1) {
return fluid == fluid1;
}
public static boolean isContainer(ItemStack stack) {
return ContainerItemContext.withInitial(stack).find(FluidStorage.ITEM) != null;
}
public static boolean isContainerEmpty(ItemStack stack) {
var fluidStorage = ContainerItemContext.withInitial(stack).find(FluidStorage.ITEM);
if (fluidStorage == null) return false;
// Use current transaction in case this check is nested in a transfer operation.
try (var tx = Transaction.openNested(Transaction.getCurrentUnsafe())) {
for (var view : fluidStorage.iterable(tx)) {
if (!view.isResourceBlank() && view.getAmount() > 0) {
return false;
}
}
}
return true;
}
public static boolean containsMatchingFluid(ItemStack stack, Predicate<Fluid> predicate) {
var fluidStorage = ContainerItemContext.withInitial(stack).find(FluidStorage.ITEM);
if (fluidStorage == null) return false;
// Use current transaction in case this check is nested in a transfer operation.
try (var tx = Transaction.openNested(Transaction.getCurrentUnsafe())) {
for (var view : fluidStorage.iterable(tx)) {
if (!view.isResourceBlank() && view.getAmount() > 0 && predicate.test(view.getResource().getFluid())) {
return true;
}
}
}
return false;
}
@Deprecated
public static boolean interactWithFluidHandler(PlayerEntity playerIn, Hand hand, Tank tank) {
// TODO
return false;
}
public static String getFluidName(@NotNull FluidInstance fluidInstance) {
// TODO: use FluidVariantRendering
return getFluidName(fluidInstance.getFluid());
}
public static String getFluidName(@NotNull Fluid fluid) {
return StringUtils.capitalize(Registry.FLUID.getId(fluid).getPath());
}
}

View file

@ -24,49 +24,21 @@
package reborncore.common.fluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.BucketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.Lazy;
import net.minecraft.util.registry.Registry;
import reborncore.common.fluid.container.ItemFluidInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public class RebornFluidManager {
private static final HashMap<Identifier, RebornFluid> fluids = new HashMap<>();
private static Lazy<Map<Fluid, BucketItem>> bucketMap;
public static void register(RebornFluid rebornFluid, Identifier identifier) {
fluids.put(identifier, rebornFluid);
Registry.register(Registry.FLUID, identifier, rebornFluid);
}
public static void setupBucketMap() {
bucketMap = new Lazy<>(() -> {
Map<Fluid, BucketItem> map = new HashMap<>();
Registry.ITEM.stream().filter(item -> item instanceof BucketItem).forEach(item -> {
BucketItem bucketItem = (BucketItem) item;
//We can be sure of this as we add this via a mixin
ItemFluidInfo fluidInfo = (ItemFluidInfo) bucketItem;
Fluid fluid = fluidInfo.getFluid(new ItemStack(item));
if (!map.containsKey(fluid)) {
map.put(fluid, bucketItem);
}
});
return map;
});
}
public static Map<Fluid, BucketItem> getBucketMap() {
return bucketMap.get();
}
public static HashMap<Identifier, RebornFluid> getFluids() {
return fluids;
}

View file

@ -22,21 +22,9 @@
* SOFTWARE.
*/
package reborncore.client.gui.slots;
package reborncore.common.misc;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import reborncore.common.fluid.FluidUtil;
public class SlotFluid extends BaseSlot {
public SlotFluid(Inventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) {
super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_);
}
@Override
public boolean canInsert(ItemStack stack) {
return FluidUtil.getFluidHandler(stack) != null;
}
}
@FunctionalInterface
public interface TriConsumer<A, B, C> {
void accept(A a, B b, C c);
}

View file

@ -225,9 +225,7 @@ public class MultiblockWorldRegistry {
}
if (newMaster == null) {
RebornCore.LOGGER.fatal(
String.format("Multiblock system checked a merge pool of size %d, found no master candidates. This should never happen.",
mergePool.size()));
RebornCore.LOGGER.error("Multiblock system checked a merge pool of size %d, found no master candidates. This should never happen., {}", mergePool.size());
} else {
// Merge all the other machines into the master machine,
// then unregister them
@ -282,8 +280,7 @@ public class MultiblockWorldRegistry {
// potentially dead.
// Validate that they are empty/dead, then unregister them.
if (!controller.isEmpty()) {
RebornCore.LOGGER.fatal(
"Found a non-empty controller. Forcing it to shed its blocks and die. This should never happen!");
RebornCore.LOGGER.error("Found a non-empty controller. Forcing it to shed its blocks and die. This should never happen!");
detachedParts.addAll(controller.detachAllBlocks());
}

View file

@ -37,8 +37,8 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import reborncore.RebornCore;
import reborncore.client.ClientChunkManager;
import reborncore.client.screen.builder.BuiltScreenHandler;
@ -46,13 +46,12 @@ import reborncore.common.blockentity.FluidConfiguration;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blockentity.SlotConfiguration;
import reborncore.common.chunkloading.ChunkLoaderManager;
import reborncore.common.util.WorldUtils;
import java.util.List;
@Environment(EnvType.CLIENT)
public class ClientBoundPacketHandlers {
private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(ClientBoundPacketHandlers.class);
public static void init() {
NetworkManager.registerClientBoundHandler(new Identifier("reborncore", "custom_description"), (client, handler, packetBuffer, responseSender) -> {

View file

@ -1,5 +1,10 @@
package reborncore.common.powerSystem;
import net.fabricmc.fabric.api.item.v1.FabricItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.api.base.SimpleBatteryItem;
/**
@ -10,7 +15,7 @@ import team.reborn.energy.api.base.SimpleBatteryItem;
* </ul>
* TODO: consider moving this functionality to the energy API?
*/
public interface RcEnergyItem extends SimpleBatteryItem {
public interface RcEnergyItem extends SimpleBatteryItem, FabricItem {
long getEnergyCapacity();
/**
@ -25,4 +30,14 @@ public interface RcEnergyItem extends SimpleBatteryItem {
default long getEnergyMaxOutput() {
return getTier().getMaxOutput();
}
@Override
default boolean allowNbtUpdateAnimation(PlayerEntity player, Hand hand, ItemStack oldStack, ItemStack newStack) {
return !ItemUtils.isEqualIgnoreEnergy(oldStack, newStack);
}
@Override
default boolean allowContinuingBlockBreaking(PlayerEntity player, ItemStack oldStack, ItemStack newStack) {
return ItemUtils.isEqualIgnoreEnergy(oldStack, newStack);
}
}

View file

@ -38,6 +38,7 @@ import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.recipes.IRecipeInput;
import team.reborn.energy.api.EnergyStorage;
import team.reborn.energy.api.EnergyStorageUtil;
import team.reborn.energy.api.base.SimpleBatteryItem;
import java.util.List;
import java.util.function.Predicate;
@ -76,6 +77,29 @@ public class ItemUtils {
return false;
}
public static boolean isEqualIgnoreEnergy(ItemStack stack1, ItemStack stack2) {
if (stack1 == stack2) {
return true;
}
if (!stack1.isOf(stack2.getItem())) {
return false;
}
if (stack1.getCount() != stack2.getCount()) {
return false;
}
if (stack1.getNbt() == stack2.getNbt()) {
return true;
}
if (stack1.getNbt() == null || stack2.getNbt() == null) {
return false;
}
NbtCompound nbt1Copy = stack1.getNbt().copy();
NbtCompound nbt2Copy = stack2.getNbt().copy();
nbt1Copy.remove(SimpleBatteryItem.ENERGY_KEY);
nbt2Copy.remove(SimpleBatteryItem.ENERGY_KEY);
return nbt1Copy.equals(nbt2Copy);
}
//TODO tags
public static boolean isInputEqual(Object input, ItemStack other, boolean matchNBT,
boolean useTags) {

View file

@ -27,7 +27,6 @@ package reborncore.common.util;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull;
import reborncore.api.items.InventoryBase;
import reborncore.common.blockentity.MachineBaseBlockEntity;
@ -95,12 +94,6 @@ public class RebornInventory<T extends MachineBaseBlockEntity> extends Inventory
return stack;
}
public RebornInventory getExternal(Direction facing) {
throw new UnsupportedOperationException("needs fixing");
//return externalInventory.withFacing(facing);
}
public void read(NbtCompound data) {
read(data, "Items");
}
@ -141,6 +134,7 @@ public class RebornInventory<T extends MachineBaseBlockEntity> extends Inventory
public void setHashChanged() {
this.hasChanged = true;
this.markDirty();
}
public void setHashChanged(boolean changed) {

View file

@ -42,9 +42,9 @@ public class MixinGameRenderer {
@Final
private MinecraftClient client;
@Redirect(method = "updateMovementFovMultiplier", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;getSpeed()F"))
private float updateMovementFovMultiplier(AbstractClientPlayerEntity playerEntity) {
float playerSpeed = playerEntity.getSpeed();
@Redirect(method = "updateFovMultiplier", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;getFovMultiplier()F"))
private float updateFovMultiplier(AbstractClientPlayerEntity playerEntity) {
float playerSpeed = playerEntity.getFovMultiplier();
for (ItemStack stack : playerEntity.getArmorItems()) {
if (stack.getItem() instanceof ArmorFovHandler) {
playerSpeed = ((ArmorFovHandler) stack.getItem()).changeFov(playerSpeed, stack, client.player);

View file

@ -31,7 +31,6 @@ import net.minecraft.item.Items;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import reborncore.common.fluid.RebornFluidManager;
import reborncore.common.fluid.container.ItemFluidInfo;
@Mixin(BucketItem.class)
@ -48,8 +47,7 @@ public class MixinBucketItem implements ItemFluidInfo {
@Override
public ItemStack getFull(Fluid fluid) {
BucketItem item = RebornFluidManager.getBucketMap().get(fluid);
return new ItemStack(item);
return new ItemStack(fluid.getBucketItem());
}
@Override

View file

@ -1,60 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.mixin.common;
import com.google.gson.JsonObject;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
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 reborncore.common.crafting.ConditionManager;
import java.util.Iterator;
import java.util.Map;
@Mixin(RecipeManager.class)
public class MixinRecipeManager {
@Inject(method = "apply", at = @At("HEAD"))
private void deserialize(Map<Identifier, JsonObject> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info) {
Iterator<Map.Entry<Identifier, JsonObject>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Identifier, JsonObject> entry = iterator.next();
Identifier id = entry.getKey();
JsonObject json = entry.getValue();
// TODO dont hard code this as its awful
if (id.getNamespace().equals("reborncore") || id.getNamespace().equals("techreborn")) {
if (!ConditionManager.shouldLoadRecipe(json)) {
iterator.remove();
}
}
}
}
}

View file

@ -1,7 +1,7 @@
{
"required": true,
"package": "reborncore.mixin.client",
"compatibilityLevel": "JAVA_16",
"compatibilityLevel": "JAVA_17",
"client": [
"MixinGameRenderer",
"MixinDebugRenderer",

View file

@ -1,7 +1,7 @@
{
"required": true,
"package": "reborncore.mixin.common",
"compatibilityLevel": "JAVA_16",
"compatibilityLevel": "JAVA_17",
"mixins": [
"AccessorFluidBlock",
"AccessorFoliagePlacerType",
@ -14,7 +14,6 @@
"MixinItemStack",
"MixinLivingEntity",
"MixinPlayerEntity",
"MixinRecipeManager",
"MixinServerPlayerEntity"
],
"injectors": {