diff --git a/build.gradle.kts b/build.gradle.kts index 822c38f..9dd8c16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,13 +2,16 @@ import java.net.URI plugins { `java-library` - eclipse idea `maven-publish` id("io.freefair.lombok") version "8.6" - id ("net.neoforged.gradle.userdev") version ("7.0.153") id("com.diffplug.spotless") version "7.0.0.BETA1" id("com.palantir.git-version") version "3.1.0" + id ("net.neoforged.gradle.userdev") version ("7.0.171") +} + +tasks.named("wrapper") { + distributionType = Wrapper.DistributionType.BIN } val minecraftVersion: String by project @@ -46,7 +49,6 @@ val versionDetails: groovy.lang.Closure /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 25da30d..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/src/main/java/xyz/robaertschi/environmenttech/command/EnvironmenttechCommand.java b/src/main/java/xyz/robaertschi/environmenttech/command/EnvironmenttechCommand.java index e2092cf..fcb8b3d 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/command/EnvironmenttechCommand.java +++ b/src/main/java/xyz/robaertschi/environmenttech/command/EnvironmenttechCommand.java @@ -21,6 +21,7 @@ import net.neoforged.neoforge.server.command.EnumArgument; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.WorldCoordinates; +import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; @@ -31,11 +32,12 @@ import com.mojang.brigadier.arguments.LongArgumentType; import xyz.robaertschi.environmenttech.data.attachments.ETAttachments; import xyz.robaertschi.environmenttech.data.capabilities.ETCapabilities; -import xyz.robaertschi.environmenttech.data.capabilities.EnvType; import static net.minecraft.commands.Commands.*; +@SuppressWarnings("resource") public class EnvironmenttechCommand { + public EnvironmenttechCommand(CommandDispatcher dispatcher) { dispatcher.register( literal("environmenttech") @@ -64,19 +66,33 @@ public class EnvironmenttechCommand { return 1; })) - .then(literal("set_env").then(argument("pos", BlockPosArgument.blockPos()).then(argument("env_type", EnumArgument.enumArgument(EnvType.class)).then(argument("amount", LongArgumentType.longArg(0)).executes( + .then(literal("set_env").then(argument("pos", BlockPosArgument.blockPos()).then(argument("amount", LongArgumentType.longArg(0)).executes( context -> { WorldCoordinates pos = context.getArgument("pos", WorldCoordinates.class); - EnvType type = context.getArgument("env_type", EnvType.class); long amount = context.getArgument("amount", Long.class); - var cap = context.getSource().getPlayerOrException().level().getCapability(ETCapabilities.ENV_STORAGE_BLOCK, pos.getBlockPos(context.getSource()), type); + + var cap = context.getSource().getPlayerOrException().level().getCapability(ETCapabilities.ENV_STORAGE_BLOCK, pos.getBlockPos(context.getSource())); if (cap != null) { cap.receiveEnv(amount, false); } return 1; } - ))))) + )).then(literal("set_bundled_env").then(argument("pos", BlockPosArgument.blockPos()).then(argument("direction", EnumArgument.enumArgument(Direction.class)).then(argument("amount", LongArgumentType.longArg(0)).executes( + context -> { + WorldCoordinates pos = context.getArgument("pos", WorldCoordinates.class); + long amount = context.getArgument("amount", Long.class); + Direction direction = context.getArgument("direction", Direction.class); + + var cap = context.getSource().getPlayerOrException().level().getCapability(ETCapabilities.ENV_BUNDLED_STORAGE_BLOCK, pos.getBlockPos(context.getSource()), direction); + if (cap != null) { + cap.receiveEnv(amount, false); + } + + return 1; + } + ))))) + )) ); } } diff --git a/src/main/java/xyz/robaertschi/environmenttech/compat/jei/EnvCollectorRecipeCategory.java b/src/main/java/xyz/robaertschi/environmenttech/compat/jei/EnvCollectorRecipeCategory.java index 56a0a75..29656a7 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/compat/jei/EnvCollectorRecipeCategory.java +++ b/src/main/java/xyz/robaertschi/environmenttech/compat/jei/EnvCollectorRecipeCategory.java @@ -16,11 +16,10 @@ */ package xyz.robaertschi.environmenttech.compat.jei; -import java.util.ArrayList; -import java.util.List; import javax.annotation.ParametersAreNonnullByDefault; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.builder.ITooltipBuilder; import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.helpers.IGuiHelper; @@ -79,11 +78,8 @@ public class EnvCollectorRecipeCategory implements IRecipeCategory recipeHolder, IFocusGroup focuses) { EnvCollectorRecipe recipe = recipeHolder.value(); - builder.addSlot(RecipeIngredientRole.INPUT, 6, 16).addIngredients(recipe.input()); - builder.addSlot(RecipeIngredientRole.OUTPUT, 68, 17).addItemStack(recipe.output()); - } @Override @@ -93,15 +89,11 @@ public class EnvCollectorRecipeCategory implements IRecipeCategory getTooltipStrings(RecipeHolder recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) { - List components = new ArrayList<>(); - + public void getTooltip(ITooltipBuilder builder, RecipeHolder recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) { int x = getWidth() - 10; if (MouseUtils.isMouseOver(Mth.floor(mouseX), Mth.floor(mouseY), x, 2, 8, 45)) { - components.add(Component.literal(recipe.value().envUsed() + " / " + 64 + " ENV")); + builder.add(Component.literal(recipe.value().envUsed() + " / " + 64 + " ENV")); } - - return components; } diff --git a/src/main/java/xyz/robaertschi/environmenttech/compat/jei/JeiCompatPlugin.java b/src/main/java/xyz/robaertschi/environmenttech/compat/jei/JeiCompatPlugin.java index 15847fe..fd65cf5 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/compat/jei/JeiCompatPlugin.java +++ b/src/main/java/xyz/robaertschi/environmenttech/compat/jei/JeiCompatPlugin.java @@ -35,7 +35,6 @@ import net.minecraft.world.item.ItemStack; import xyz.robaertschi.environmenttech.ET; import xyz.robaertschi.environmenttech.data.recipes.ETRecipes; import xyz.robaertschi.environmenttech.level.block.ETBlocks; -import xyz.robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity; import xyz.robaertschi.environmenttech.menu.ETMenus; import xyz.robaertschi.environmenttech.menu.EnvCollectorMenu; @@ -68,9 +67,9 @@ public class JeiCompatPlugin implements IModPlugin { @Override public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { registration.addRecipeTransferHandler(EnvCollectorMenu.class, ETMenus.ENV_COLLECTOR_MENU.get(), EnvCollectorRecipeCategory.ENV_COLLECTOR, - EnvCollectorBlockEntity.SLOT_INPUT, - EnvCollectorBlockEntity.SLOT_INPUT_COUNT, - EnvCollectorBlockEntity.SLOT_COUNT, + 0, + 1, + 2, Inventory.INVENTORY_SIZE); } } diff --git a/src/main/java/xyz/robaertschi/environmenttech/compat/top/TopCompat.java b/src/main/java/xyz/robaertschi/environmenttech/compat/top/TopCompat.java index fe0ebee..a93c4e3 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/compat/top/TopCompat.java +++ b/src/main/java/xyz/robaertschi/environmenttech/compat/top/TopCompat.java @@ -24,6 +24,7 @@ import net.neoforged.fml.InterModComms; import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent; import net.neoforged.neoforge.capabilities.BlockCapabilityCache; +import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; @@ -34,7 +35,7 @@ import xyz.robaertschi.environmenttech.ET; import xyz.robaertschi.environmenttech.EnvironmentTech; import xyz.robaertschi.environmenttech.client.renderer.EnvStorageRenderer; import xyz.robaertschi.environmenttech.data.capabilities.ETCapabilities; -import xyz.robaertschi.environmenttech.data.capabilities.EnvType; +import xyz.robaertschi.environmenttech.data.capabilities.IBundledEnvStorage; import xyz.robaertschi.environmenttech.data.capabilities.IEnvStorage; public class TopCompat { @@ -54,7 +55,8 @@ public class TopCompat { probe = theOneProbe; EnvironmentTech.LOGGER.info("Enabled TheOneProbe support"); theOneProbe.registerProvider(new IProbeInfoProvider() { - private BlockCapabilityCache capCache = null; + private BlockCapabilityCache capCache = null; + private BlockCapabilityCache bundledCapCache = null; @Override public ResourceLocation getID() { @@ -71,14 +73,11 @@ public class TopCompat { if (!(level instanceof ServerLevel)) return; if (capCache == null || !capCache.pos().equals(iProbeHitData.getPos())) { - capCache = BlockCapabilityCache.create(ETCapabilities.ENV_STORAGE_BLOCK, (ServerLevel) level, iProbeHitData.getPos(), EnvType.Normal); - // Try other env types - if (capCache.getCapability() == null) { - capCache = BlockCapabilityCache.create(ETCapabilities.ENV_STORAGE_BLOCK, (ServerLevel) level, iProbeHitData.getPos(), EnvType.Bundled); - } - if (capCache.getCapability() == null) { - capCache = BlockCapabilityCache.create(ETCapabilities.ENV_STORAGE_BLOCK, (ServerLevel) level, iProbeHitData.getPos(), EnvType.Chunk); - } + capCache = BlockCapabilityCache.create(ETCapabilities.ENV_STORAGE_BLOCK, (ServerLevel) level, iProbeHitData.getPos(), null); + } + // Try other env types + if (bundledCapCache == null || !capCache.pos().equals(iProbeHitData.getPos())) { + bundledCapCache = BlockCapabilityCache.create(ETCapabilities.ENV_BUNDLED_STORAGE_BLOCK, (ServerLevel) level, iProbeHitData.getPos(), null); } IEnvStorage cap = capCache.getCapability(); @@ -89,6 +88,15 @@ public class TopCompat { .suffix(" ENV"); iProbeInfo.horizontal().progress(cap.getEnvStored(),cap.getMaxEnv(), style); } + + IBundledEnvStorage bundledCap = bundledCapCache.getCapability(); + if (bundledCap != null) { + var style = iProbeInfo.defaultProgressStyle() + .filledColor(EnvStorageRenderer.from) + .alternateFilledColor(EnvStorageRenderer.to) + .suffix(" Bundled ENV"); + iProbeInfo.horizontal().progress(bundledCap.getEnvStored(), bundledCap.getMaxEnv(), style); + } } }); diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/ETCapabilities.java b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/ETCapabilities.java index c511c60..637253b 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/ETCapabilities.java +++ b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/ETCapabilities.java @@ -27,11 +27,13 @@ import xyz.robaertschi.environmenttech.ET; import xyz.robaertschi.environmenttech.level.block.entity.ETBlockEntities; public class ETCapabilities { - public static final BlockCapability ENV_STORAGE_BLOCK = - BlockCapability.create(ET.id("env_storage"), - IEnvStorage.class, - EnvType.class - ); + public static final BlockCapability ENV_STORAGE_BLOCK = + BlockCapability.createVoid(ET.id("env_storage"), + IEnvStorage.class); + + public static final BlockCapability ENV_BUNDLED_STORAGE_BLOCK = + BlockCapability.create(ET.id("env_bundled_storage"), + IBundledEnvStorage.class, Direction.class); public static void init(IEventBus iEventBus) { iEventBus.addListener(ETCapabilities::registerCapabilities); @@ -55,19 +57,13 @@ public class ETCapabilities { event.registerBlockEntity( ENV_STORAGE_BLOCK, ETBlockEntities.ENV_COLLECTOR_BLOCK_ENTITY.get(), - (object, context) -> { - if (context == EnvType.Chunk) return object.getEnvStorage(); - return null; - } + (object, context) -> object.getEnvStorage() ); event.registerBlockEntity( ENV_STORAGE_BLOCK, ETBlockEntities.ENV_DISTRIBUTOR_BLOCK_ENTITY.get(), - (object, context) -> { - if (context == EnvType.Chunk) return object.getEnvStorage(); - return null; - } + (object, context) -> object.getEnvStorage() ); } diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvStorage.java b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvStorage.java index 9c9e50d..7f6729d 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvStorage.java +++ b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvStorage.java @@ -20,34 +20,20 @@ import net.minecraft.util.Mth; @SuppressWarnings("unused") public class EnvStorage implements IEnvStorage { - private final EnvType[] acceptedEnvTypes; private final long maxEnv; private long env; private final long maxTransfer; - public EnvStorage(EnvType acceptedEnvType, long maxEnv, long env, long maxTransfer) { - this.acceptedEnvTypes = new EnvType[1]; - this.acceptedEnvTypes[0] = acceptedEnvType; + public EnvStorage(long maxEnv) { + this(maxEnv, 0, maxEnv); + } + + public EnvStorage(long maxEnv, long env, long maxTransfer) { this.maxEnv = maxEnv; this.env = env; this.maxTransfer = maxTransfer; } - public EnvStorage(EnvType acceptedEnvType, long maxEnv) { - this(acceptedEnvType, maxEnv, 0, maxEnv); - } - - public EnvStorage(EnvType[] acceptedEnvTypes, long maxEnv, long env, long maxTransfer) { - this.acceptedEnvTypes = acceptedEnvTypes; - this.maxEnv = maxEnv; - this.env = env; - this.maxTransfer = maxTransfer; - } - - public EnvStorage(EnvType[] acceptedEnvTypes, long maxEnv) { - this(acceptedEnvTypes, maxEnv, 0, maxEnv); - } - @Override public long receiveEnv(long amount, boolean simulate) { long received = Mth.clamp(this.maxEnv - this.env, 0, Math.min(amount, maxTransfer)); @@ -73,10 +59,5 @@ public class EnvStorage implements IEnvStorage { return maxEnv; } - @Override - public EnvType[] canAcceptEnvType() { - return acceptedEnvTypes; - } - public void onContentsChanged() {} } diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IBundledEnvStorage.java b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IBundledEnvStorage.java new file mode 100644 index 0000000..f170fdf --- /dev/null +++ b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IBundledEnvStorage.java @@ -0,0 +1,36 @@ +/* + * EnvironmentTech MC Mod + Copyright (C) 2024 Robin Bärtschi and Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, by version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + */ +package xyz.robaertschi.environmenttech.data.capabilities; + +/** + * ENV is pushed based, so you should not be able to extract ENV from anything. + * This is the reason for the nonexistent extract method. + * This is currently the same as {@link IEnvStorage}. This will however change sometime. Also they are not the same. + * Bundled Env Storage is per Cable, which has a {@link net.minecraft.core.Direction} while the Normal Storage doesn't. + */ +public interface IBundledEnvStorage { + /** + * Receive ENV. + * @param amount The Amount of ENV to receive. + * @param simulate If the operation is to only be simulated and not affect the storage amount + * @return How much energy was accepted. + */ + long receiveEnv(long amount, boolean simulate); + + long getEnvStored(); + long getMaxEnv(); +} diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IEnvStorage.java b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IEnvStorage.java index 7ed6c21..9e1ad1a 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IEnvStorage.java +++ b/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/IEnvStorage.java @@ -32,10 +32,4 @@ public interface IEnvStorage { long getEnvStored(); long getMaxEnv(); - - - /** - * @return Which ENVType's that are supported. - */ - EnvType[] canAcceptEnvType(); } diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/components/ETComponents.java b/src/main/java/xyz/robaertschi/environmenttech/data/components/ETComponents.java index c20b2f5..706baff 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/data/components/ETComponents.java +++ b/src/main/java/xyz/robaertschi/environmenttech/data/components/ETComponents.java @@ -21,12 +21,13 @@ import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.Registries; import xyz.robaertschi.environmenttech.ET; public class ETComponents { - public static final DeferredRegister.DataComponents DATA_COMPONENTS = DeferredRegister.createDataComponents(ET.MODID); + public static final DeferredRegister.DataComponents DATA_COMPONENTS = DeferredRegister.createDataComponents(Registries.DATA_COMPONENT_TYPE, ET.MODID); public static final DeferredHolder, DataComponentType> FILLED_COMPONENT = DATA_COMPONENTS.registerComponentType("filled_component", filledComponentBuilder -> filledComponentBuilder.persistent(FilledComponent.CODEC).networkSynchronized(FilledComponent.STREAM_CODEC) diff --git a/src/main/java/xyz/robaertschi/environmenttech/datagen/ETBlockStateProvider.java b/src/main/java/xyz/robaertschi/environmenttech/datagen/ETBlockStateProvider.java index dca7558..7af73d9 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/datagen/ETBlockStateProvider.java +++ b/src/main/java/xyz/robaertschi/environmenttech/datagen/ETBlockStateProvider.java @@ -36,5 +36,6 @@ public class ETBlockStateProvider extends BlockStateProvider { // registerEnvCollector(); horizontalBlock(ETBlocks.ENV_COLLECTOR_BLOCK.get(), new ModelFile.UncheckedModelFile(modLoc("block/env_collector"))); horizontalBlock(ETBlocks.ENV_DISTRIBUTOR_BLOCK.get(), new ModelFile.UncheckedModelFile(modLoc("block/env_distributor"))); + horizontalBlock(ETBlocks.HEAT_GENERATOR_BLOCK.get(), new ModelFile.UncheckedModelFile(modLoc("block/heat_generator"))); } } diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/ETBlocks.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/ETBlocks.java index 7e8216f..dabd885 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/level/block/ETBlocks.java +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/ETBlocks.java @@ -23,6 +23,7 @@ import net.neoforged.neoforge.registries.DeferredRegister; import net.minecraft.world.level.block.state.BlockBehaviour; import xyz.robaertschi.environmenttech.ET; +import xyz.robaertschi.environmenttech.level.block.generators.HeatGeneratorBlock; public class ETBlocks { @@ -31,7 +32,8 @@ public class ETBlocks { // Creates a new Block with the id "environmenttech:example_block", combining the namespace and path // public static final DeferredBlock EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE)); public static final DeferredBlock ENV_COLLECTOR_BLOCK = BLOCKS.registerBlock("env_collector", EnvCollectorBlock::new, BlockBehaviour.Properties.of()); - public static final DeferredBlock ENV_DISTRIBUTOR_BLOCK =BLOCKS.registerBlock("env_distributor", EnvDistributorBlock::new, BlockBehaviour.Properties.of()); + public static final DeferredBlock ENV_DISTRIBUTOR_BLOCK = BLOCKS.registerBlock("env_distributor", EnvDistributorBlock::new, BlockBehaviour.Properties.of()); + public static final DeferredBlock HEAT_GENERATOR_BLOCK = BLOCKS.registerBlock("heat_generator", HeatGeneratorBlock::new, BlockBehaviour.Properties.of()); public static void init(IEventBus iEventBus) { diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/ETBlockEntities.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/ETBlockEntities.java index c160456..e836261 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/ETBlockEntities.java +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/ETBlockEntities.java @@ -41,6 +41,11 @@ public class ETBlockEntities { BLOCK_ENTITIES.register("env_distributor", () -> BlockEntityType.Builder.of(EnvDistributorBlockEntity::new, ETBlocks.ENV_DISTRIBUTOR_BLOCK.get()).build(null)); + public static final DeferredHolder, BlockEntityType> HEAT_GENERATOR_BLOCK_ENTITY = + BLOCK_ENTITIES.register("heat_generator", + () -> BlockEntityType.Builder.of(HeatGeneratorBlockEntity::new, ETBlocks.HEAT_GENERATOR_BLOCK.get()).build(null) + ); + public static void init(IEventBus iEventBus) { BLOCK_ENTITIES.register(iEventBus); } diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvCollectorBlockEntity.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvCollectorBlockEntity.java index b2f150e..d014847 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvCollectorBlockEntity.java +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvCollectorBlockEntity.java @@ -55,7 +55,6 @@ import xyz.robaertschi.environmenttech.compat.top.TOPInfoProvider; import xyz.robaertschi.environmenttech.data.attachments.ETAttachments; import xyz.robaertschi.environmenttech.data.capabilities.AdaptedItemHandler; import xyz.robaertschi.environmenttech.data.capabilities.EnvStorage; -import xyz.robaertschi.environmenttech.data.capabilities.EnvType; import xyz.robaertschi.environmenttech.data.recipes.ETRecipes; import xyz.robaertschi.environmenttech.data.recipes.EnvCollectorRecipe; import xyz.robaertschi.environmenttech.menu.EnvCollectorMenu; @@ -87,7 +86,7 @@ public class EnvCollectorBlockEntity extends BlockEntity implements MenuProvider } }; @Getter - private final ItemStackHandler outputInventory = new ItemStackHandler(SLOT_INPUT_COUNT) { + private final ItemStackHandler outputInventory = new ItemStackHandler(SLOT_OUTPUT_COUNT) { protected void onContentsChanged(int slot) { EnvCollectorBlockEntity.this.setChanged(); assert level != null; @@ -133,7 +132,7 @@ public class EnvCollectorBlockEntity extends BlockEntity implements MenuProvider @Getter - private final EnvStorage envStorage = new EnvStorage(EnvType.Chunk, 64, 0, 1) { + private final EnvStorage envStorage = new EnvStorage(64, 0, 1) { @Override public void onContentsChanged() { EnvCollectorBlockEntity.this.setChanged(); diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvDistributorBlockEntity.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvDistributorBlockEntity.java index 0ac92c7..22ac9e6 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvDistributorBlockEntity.java +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/EnvDistributorBlockEntity.java @@ -38,7 +38,6 @@ import net.minecraft.world.level.chunk.ChunkAccess; import xyz.robaertschi.environmenttech.ET; import xyz.robaertschi.environmenttech.data.attachments.ETAttachments; import xyz.robaertschi.environmenttech.data.capabilities.EnvStorage; -import xyz.robaertschi.environmenttech.data.capabilities.EnvType; @Getter @@ -51,7 +50,7 @@ public class EnvDistributorBlockEntity extends BlockEntity implements ITickableB private int ticksBetweenProcessTick = 0; public static final String ENV_TAG = "Env"; - private final EnvStorage envStorage = new EnvStorage(EnvType.Chunk, 64) { + private final EnvStorage envStorage = new EnvStorage(64) { @Override public void onContentsChanged() { EnvDistributorBlockEntity.this.setChanged(); diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/HeatGeneratorBlockEntity.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/HeatGeneratorBlockEntity.java new file mode 100644 index 0000000..1e83734 --- /dev/null +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/entity/HeatGeneratorBlockEntity.java @@ -0,0 +1,82 @@ +/* + * EnvironmentTech MC Mod + Copyright (C) 2024 Robin Bärtschi and Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, by version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + */ +package xyz.robaertschi.environmenttech.level.block.entity; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; + +import org.jetbrains.annotations.NotNull; +import xyz.robaertschi.environmenttech.ET; +import xyz.robaertschi.environmenttech.data.capabilities.EnvStorage; + +public class HeatGeneratorBlockEntity extends BlockEntity implements ITickableBlockEntity { + private static final HashMap BLOCK_TO_ENV = new HashMap<>(Map.of(Blocks.TORCH, 1L, Blocks.FIRE, 3L, Blocks.CAMPFIRE, 5L, Blocks.SOUL_TORCH, 6L, Blocks.SOUL_FIRE, 8L, Blocks.SOUL_CAMPFIRE, 10L, Blocks.LAVA, 14L)); + + public static final String ENV_TAG = "Env"; + private final EnvStorage envStorage = new EnvStorage(64) { + @Override + public void onContentsChanged() { + HeatGeneratorBlockEntity.this.setChanged(); + assert level != null; + if (!level.isClientSide()) { + level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_ALL); + } + } + + @Override + public void setEnvStored(long env) { + super.setEnvStored(env); + if (level != null && !level.isClientSide()) { + level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_ALL); + } + } + }; + + public HeatGeneratorBlockEntity(BlockPos pos, BlockState blockState) { + super(ETBlockEntities.HEAT_GENERATOR_BLOCK_ENTITY.get(), pos, blockState); + } + + @Override + public void serverTick(ServerLevel level, BlockPos blockPos, BlockState blockState) { + var toAdd = BLOCK_TO_ENV.getOrDefault(level.getBlockState(blockPos.below()).getBlock(), 0L); + envStorage.receiveEnv(toAdd, false); + } + + @Override + protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) { + super.loadAdditional(tag, registries); + CompoundTag modData = tag.getCompound(ET.MODID); + this.envStorage.setEnvStored(modData.getLong(ENV_TAG)); + } + + @Override + protected void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) { + super.saveAdditional(tag, registries); + CompoundTag modData = new CompoundTag(); + modData.putLong(ENV_TAG, envStorage.getEnvStored()); + tag.put(ET.MODID, modData); + } +} diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/block/generators/HeatGeneratorBlock.java b/src/main/java/xyz/robaertschi/environmenttech/level/block/generators/HeatGeneratorBlock.java new file mode 100644 index 0000000..262216a --- /dev/null +++ b/src/main/java/xyz/robaertschi/environmenttech/level/block/generators/HeatGeneratorBlock.java @@ -0,0 +1,54 @@ +/* + * EnvironmentTech MC Mod + Copyright (C) 2024 Robin Bärtschi and Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, by version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + */ +package xyz.robaertschi.environmenttech.level.block.generators; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; + +import com.mojang.serialization.MapCodec; + +import xyz.robaertschi.environmenttech.level.block.SimpleBlockWithEntity; +import xyz.robaertschi.environmenttech.level.block.entity.ETBlockEntities; +import xyz.robaertschi.environmenttech.level.block.entity.HeatGeneratorBlockEntity; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +public class HeatGeneratorBlock extends SimpleBlockWithEntity { + public static final MapCodec CODEC = simpleCodec(HeatGeneratorBlock::new); + + public HeatGeneratorBlock(Properties pProperties) { + super(pProperties, ETBlockEntities.HEAT_GENERATOR_BLOCK_ENTITY); + } + + @Override + protected MapCodec codec() { + return CODEC; + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new HeatGeneratorBlockEntity(pos, state); + } +} diff --git a/src/main/java/xyz/robaertschi/environmenttech/level/fluid/ETFluidTypes.java b/src/main/java/xyz/robaertschi/environmenttech/level/fluid/ETFluidTypes.java index 0b45662..a0cd842 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/level/fluid/ETFluidTypes.java +++ b/src/main/java/xyz/robaertschi/environmenttech/level/fluid/ETFluidTypes.java @@ -16,17 +16,16 @@ */ package xyz.robaertschi.environmenttech.level.fluid; -import java.util.function.Consumer; -import javax.annotation.ParametersAreNonnullByDefault; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.NeoForgeRegistries; +import org.jetbrains.annotations.NotNull; -import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.resources.ResourceLocation; import xyz.robaertschi.environmenttech.ET; @@ -43,32 +42,30 @@ public class ETFluidTypes { public static final DeferredHolder ENV = FLUID_TYPES.register("env", resourceLocation -> new FluidType( FluidType.Properties.create().density(15).viscosity(5) - ) { - @Override - @MethodsReturnNonnullByDefault - @ParametersAreNonnullByDefault - public void initializeClient(Consumer consumer) { - consumer.accept(new IClientFluidTypeExtensions() { - @Override - public int getTintColor() { - return EnvStorageRenderer.to; - } - - @Override - public ResourceLocation getFlowingTexture() { - return WATER_FLOWING_RL; - } - - @Override - public ResourceLocation getStillTexture() { - return WATER_STILL_RL; - } - }); - } - } + ) ); + public static void registerClientExtensionsEvent(RegisterClientExtensionsEvent event) { + event.registerFluidType(new IClientFluidTypeExtensions() { + @Override + public int getTintColor() { + return EnvStorageRenderer.to; + } + + @Override + public @NotNull ResourceLocation getFlowingTexture() { + return WATER_FLOWING_RL; + } + + @Override + public @NotNull ResourceLocation getStillTexture() { + return WATER_STILL_RL; + } + }, ENV); + } + public static void init(IEventBus modEventBus) { + modEventBus.addListener(ETFluidTypes::registerClientExtensionsEvent); FLUID_TYPES.register(modEventBus); } } diff --git a/src/main/java/xyz/robaertschi/environmenttech/menu/EnvCollectorMenu.java b/src/main/java/xyz/robaertschi/environmenttech/menu/EnvCollectorMenu.java index 775dbe0..8156223 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/menu/EnvCollectorMenu.java +++ b/src/main/java/xyz/robaertschi/environmenttech/menu/EnvCollectorMenu.java @@ -31,10 +31,9 @@ import net.minecraft.world.item.ItemStack; import xyz.robaertschi.environmenttech.level.block.ETBlocks; import xyz.robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity; -import static xyz.robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity.SLOT_COUNT; -import static xyz.robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity.SLOT_INPUT; +import static xyz.robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity.*; -@SuppressWarnings("SameParameterValue") +@SuppressWarnings("ALL") public class EnvCollectorMenu extends AbstractContainerMenu { @Getter @@ -49,13 +48,12 @@ public class EnvCollectorMenu extends AbstractContainerMenu { super(ETMenus.ENV_COLLECTOR_MENU.get(), pContainerId); this.blockEntity = blockEntity; this.data = data; - addSlot(new SlotItemHandler(blockEntity.getInputInventory(), 0, 54, 34)); - addSlot(new SlotItemHandler(blockEntity.getOutputInventory(), 0, 116, 35)); + addSlot(new ModifiableSlotItemHandler(blockEntity.getInventory().get(), 0, 54, 34)); + addSlot(new SlotItemHandler(blockEntity.getInventory().get(), 1, 116, 35)); layoutPlayerInventorySlots(player.getInventory(), 8, 84); - addDataSlots(data); } @@ -107,7 +105,7 @@ public class EnvCollectorMenu extends AbstractContainerMenu { } } - if (!this.moveItemStackTo(stack, SLOT_INPUT, SLOT_INPUT+1, false)) { + if (!this.moveItemStackTo(stack, SLOT_INPUT, SLOT_INPUT_COUNT, false)) { if (pIndex < 27 + SLOT_COUNT) { if (!this.moveItemStackTo(stack, 27 + SLOT_COUNT, 36 + SLOT_COUNT, false)) { return ItemStack.EMPTY; diff --git a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvType.java b/src/main/java/xyz/robaertschi/environmenttech/menu/ModifiableSlotItemHandler.java similarity index 55% rename from src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvType.java rename to src/main/java/xyz/robaertschi/environmenttech/menu/ModifiableSlotItemHandler.java index 856ca4f..3f3dc07 100644 --- a/src/main/java/xyz/robaertschi/environmenttech/data/capabilities/EnvType.java +++ b/src/main/java/xyz/robaertschi/environmenttech/menu/ModifiableSlotItemHandler.java @@ -14,10 +14,21 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -package xyz.robaertschi.environmenttech.data.capabilities; +package xyz.robaertschi.environmenttech.menu; -public enum EnvType { - Chunk, - Normal, - Bundled, +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.SlotItemHandler; +import org.jetbrains.annotations.NotNull; + +import net.minecraft.world.entity.player.Player; + +public class ModifiableSlotItemHandler extends SlotItemHandler { + public ModifiableSlotItemHandler(IItemHandler itemHandler, int index, int xPosition, int yPosition) { + super(itemHandler, index, xPosition, yPosition); + } + + @Override + public boolean allowModification(@NotNull Player player) { + return true; + } }