mirror of
https://github.com/RoBaertschi/EnvironmentTech.git
synced 2025-04-19 23:03:28 +00:00
Start EnvCollector
This commit is contained in:
parent
35f54c29ca
commit
50e36869ce
@ -1,8 +1,8 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id ("java-library")
|
`java-library`
|
||||||
id ("eclipse")
|
eclipse
|
||||||
id ("idea")
|
idea
|
||||||
id ("maven-publish")
|
`maven-publish`
|
||||||
id ("net.neoforged.gradle.userdev") version ("7.0.138")
|
id ("net.neoforged.gradle.userdev") version ("7.0.138")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.food.FoodProperties;
|
import net.minecraft.world.food.FoodProperties;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
@ -33,6 +34,7 @@ import net.neoforged.neoforge.registries.DeferredItem;
|
|||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import robaertschi.environmenttech.data.attachments.ETAttachments;
|
import robaertschi.environmenttech.data.attachments.ETAttachments;
|
||||||
|
import robaertschi.environmenttech.data.capabilities.ETCapabilities;
|
||||||
import robaertschi.environmenttech.level.block.ETBlocks;
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
import robaertschi.environmenttech.level.item.ETItems;
|
import robaertschi.environmenttech.level.item.ETItems;
|
||||||
|
|
||||||
@ -44,8 +46,9 @@ public class EnvironmentTech
|
|||||||
public static final String MODID = "environmenttech";
|
public static final String MODID = "environmenttech";
|
||||||
public static final Logger LOGGER = LogUtils.getLogger();
|
public static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
|
public static ResourceLocation id(String name) {
|
||||||
|
return new ResourceLocation(MODID, name);
|
||||||
|
}
|
||||||
|
|
||||||
// The constructor for the mod class is the first code that is run when your mod is loaded.
|
// The constructor for the mod class is the first code that is run when your mod is loaded.
|
||||||
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
|
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
|
||||||
@ -56,6 +59,7 @@ public class EnvironmentTech
|
|||||||
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
|
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
|
||||||
|
|
||||||
ETAttachments.init(modEventBus);
|
ETAttachments.init(modEventBus);
|
||||||
|
ETCapabilities.init(modEventBus);
|
||||||
ETBlocks.init(modEventBus);
|
ETBlocks.init(modEventBus);
|
||||||
ETItems.init(modEventBus);
|
ETItems.init(modEventBus);
|
||||||
|
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package robaertschi.environmenttech.data.capabilities;
|
||||||
|
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.neoforge.capabilities.BlockCapability;
|
||||||
|
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
|
||||||
|
import robaertschi.environmenttech.EnvironmentTech;
|
||||||
|
|
||||||
|
public class ETCapabilities {
|
||||||
|
public static final BlockCapability<IEnvStorage, EnvCapabilityContext> ENV_STORAGE_BLOCK =
|
||||||
|
BlockCapability.create(EnvironmentTech.id("env_storage"),
|
||||||
|
IEnvStorage.class,
|
||||||
|
EnvCapabilityContext.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void init(IEventBus iEventBus) {
|
||||||
|
iEventBus.addListener(ETCapabilities::registerCapabilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerCapabilities(RegisterCapabilitiesEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package robaertschi.environmenttech.data.capabilities;
|
||||||
|
|
||||||
|
public record EnvCapabilityContext(EnvType type) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package robaertschi.environmenttech.data.capabilities;
|
||||||
|
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
|
// TODO: Add max receive or something
|
||||||
|
public class EnvStorage implements IEnvStorage {
|
||||||
|
private final EnvType[] acceptedEnvTypes;
|
||||||
|
private final long maxEnv;
|
||||||
|
private long env;
|
||||||
|
|
||||||
|
public EnvStorage(EnvType acceptedEnvType, long maxEnv, long env) {
|
||||||
|
this.acceptedEnvTypes = new EnvType[1];
|
||||||
|
this.acceptedEnvTypes[0] = acceptedEnvType;
|
||||||
|
this.maxEnv = maxEnv;
|
||||||
|
this.env = env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnvStorage(EnvType acceptedEnvType, long maxEnv) {
|
||||||
|
this(acceptedEnvType, maxEnv, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnvStorage(EnvType[] acceptedEnvTypes, long maxEnv, long env) {
|
||||||
|
this.acceptedEnvTypes = acceptedEnvTypes;
|
||||||
|
this.maxEnv = maxEnv;
|
||||||
|
this.env = env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnvStorage(EnvType[] acceptedEnvTypes, long maxEnv) {
|
||||||
|
this(acceptedEnvTypes, maxEnv, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long receiveEnv(long amount, boolean simulate) {
|
||||||
|
long received = Mth.clamp(this.maxEnv - this.env, 0, amount);
|
||||||
|
if (!simulate)
|
||||||
|
env += received;
|
||||||
|
|
||||||
|
return received;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getEnvStored() {
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getMaxEnv() {
|
||||||
|
return maxEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnvType[] canAcceptEnvType() {
|
||||||
|
return acceptedEnvTypes;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package robaertschi.environmenttech.data.capabilities;
|
||||||
|
|
||||||
|
public enum EnvType {
|
||||||
|
Chunk,
|
||||||
|
Normal,
|
||||||
|
Bundled,
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package 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.
|
||||||
|
*/
|
||||||
|
public interface IEnvStorage {
|
||||||
|
/**
|
||||||
|
* Receive ENV.
|
||||||
|
* The type is provided in {@link EnvCapabilityContext}
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Which ENVType's that are supported.
|
||||||
|
*/
|
||||||
|
EnvType[] canAcceptEnvType();
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package robaertschi.environmenttech.level.block;
|
||||||
|
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.util.ExtraCodecs;
|
||||||
|
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.EntityBlock;
|
||||||
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault()
|
||||||
|
public class EnvCollectorBlock extends BaseEntityBlock {
|
||||||
|
public static final MapCodec<EnvCollectorBlock> CODEC = simpleCodec(EnvCollectorBlock::new);
|
||||||
|
|
||||||
|
public EnvCollectorBlock(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
protected @NotNull RenderShape getRenderShape(BlockState pState) {
|
||||||
|
return RenderShape.MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package robaertschi.environmenttech.level.block.entity;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
public class EnvCollectorBlockEntity extends BlockEntity {
|
||||||
|
public EnvCollectorBlockEntity(BlockEntityType<?> pType, BlockPos pPos, BlockState pBlockState) {
|
||||||
|
super(pType, pPos, pBlockState);
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,8 @@ public class ETItems {
|
|||||||
.durability(10)
|
.durability(10)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final DeferredItem<Item> ENVIRONMENTAL_ESSENCE = ITEMS.registerSimpleItem("environmental_essence");
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> CREATE_MODE_TAB = CREATIVE_MODE_TABS.register("environmenttech", () -> CreativeModeTab.builder()
|
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> CREATE_MODE_TAB = CREATIVE_MODE_TABS.register("environmenttech", () -> CreativeModeTab.builder()
|
||||||
@ -43,6 +45,7 @@ public class ETItems {
|
|||||||
.displayItems((parameters, output) -> {
|
.displayItems((parameters, output) -> {
|
||||||
output.accept(ENV_DETECTOR_ITEM.get());
|
output.accept(ENV_DETECTOR_ITEM.get());
|
||||||
output.accept(EXAMPLE_BLOCK_ITEM.get());
|
output.accept(EXAMPLE_BLOCK_ITEM.get());
|
||||||
|
output.accept(ENVIRONMENTAL_ESSENCE.get());
|
||||||
}).build());
|
}).build());
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"item.environmenttech.env_detector": "ENV Detector",
|
"item.environmenttech.env_detector": "ENV Detector",
|
||||||
|
"item.environmenttech.environmental_essence": "Environmental Essence",
|
||||||
|
|
||||||
"itemGroup.environmenttech": "Environment Tech"
|
"itemGroup.environmenttech": "Environment Tech"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user