mirror of
https://github.com/RoBaertschi/EnvironmentTech.git
synced 2025-04-20 07:03:30 +00:00
continue env distributor
This commit is contained in:
parent
c57cb36bd8
commit
a653a10ae8
@ -12,7 +12,7 @@ minecraftVersion=1.20.6
|
|||||||
# as they do not follow standard versioning conventions.
|
# as they do not follow standard versioning conventions.
|
||||||
minecraftVersionRange=[1.20.6,1.21)
|
minecraftVersionRange=[1.20.6,1.21)
|
||||||
# The Neo version must agree with the Minecraft version to get a valid artifact
|
# The Neo version must agree with the Minecraft version to get a valid artifact
|
||||||
neoVersion=20.6.113-beta
|
neoVersion=20.6.115
|
||||||
# The Neo version range can use any version of Neo as bounds
|
# The Neo version range can use any version of Neo as bounds
|
||||||
neoVersionRange=[20,)
|
neoVersionRange=[20,)
|
||||||
# The loader version range can only use the major version of FML as bounds
|
# The loader version range can only use the major version of FML as bounds
|
||||||
|
@ -13,6 +13,7 @@ public class ETBlocks {
|
|||||||
// Creates a new Block with the id "environmenttech:example_block", combining the namespace and path
|
// Creates a new Block with the id "environmenttech:example_block", combining the namespace and path
|
||||||
// public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
|
// public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
|
||||||
public static final DeferredBlock<EnvCollectorBlock> ENV_COLLECTOR_BLOCK = BLOCKS.registerBlock("env_collector", EnvCollectorBlock::new, BlockBehaviour.Properties.of());
|
public static final DeferredBlock<EnvCollectorBlock> ENV_COLLECTOR_BLOCK = BLOCKS.registerBlock("env_collector", EnvCollectorBlock::new, BlockBehaviour.Properties.of());
|
||||||
|
public static final DeferredBlock<EnvDistributorBlock> ENV_DISTRIBUTOR_BLOCK =BLOCKS.registerBlock("env_distributor", EnvDistributorBlock::new, BlockBehaviour.Properties.of());
|
||||||
|
|
||||||
|
|
||||||
public static void init(IEventBus iEventBus) {
|
public static void init(IEventBus iEventBus) {
|
||||||
|
@ -7,19 +7,21 @@ import net.minecraft.world.level.Level;
|
|||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.block.*;
|
import net.minecraft.world.level.block.*;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class EnvDistributor extends BaseEntityBlock {
|
public class EnvDistributorBlock extends BaseEntityBlock {
|
||||||
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
||||||
public static final MapCodec<EnvDistributor> CODEC = simpleCodec(EnvDistributor::new);
|
public static final MapCodec<EnvDistributorBlock> CODEC = simpleCodec(EnvDistributorBlock::new);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public EnvDistributor(Properties pProperties) {
|
public EnvDistributorBlock(Properties pProperties) {
|
||||||
super(pProperties);
|
super(pProperties);
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import net.neoforged.bus.api.IEventBus;
|
|||||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
import robaertschi.environmenttech.level.block.ETBlocks;
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
|
import robaertschi.environmenttech.level.block.EnvDistributorBlock;
|
||||||
|
|
||||||
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ public class ETBlockEntities {
|
|||||||
() -> BlockEntityType.Builder.of(EnvCollectorBlockEntity::new,
|
() -> BlockEntityType.Builder.of(EnvCollectorBlockEntity::new,
|
||||||
ETBlocks.ENV_COLLECTOR_BLOCK.get()).build(null));
|
ETBlocks.ENV_COLLECTOR_BLOCK.get()).build(null));
|
||||||
|
|
||||||
|
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<EnvDistributorBlockEntity>> ENV_DISTRIBUTOR_BLOCK_ENTITY =
|
||||||
|
BLOCK_ENTITIES.register("env_distributor",
|
||||||
|
() -> BlockEntityType.Builder.of(EnvDistributorBlockEntity::new, ETBlocks.ENV_DISTRIBUTOR_BLOCK.get()).build(null));
|
||||||
|
|
||||||
public static void init(IEventBus iEventBus) {
|
public static void init(IEventBus iEventBus) {
|
||||||
BLOCK_ENTITIES.register(iEventBus);
|
BLOCK_ENTITIES.register(iEventBus);
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,6 @@ public class EnvCollectorBlockEntity extends BlockEntity implements MenuProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void produce(ServerLevel level) {
|
private void produce(ServerLevel level) {
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
package robaertschi.environmenttech.level.block.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
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 net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import robaertschi.environmenttech.data.attachments.ETAttachments;
|
||||||
|
import robaertschi.environmenttech.data.capabilities.EnvStorage;
|
||||||
|
import robaertschi.environmenttech.data.capabilities.EnvType;
|
||||||
|
import robaertschi.environmenttech.data.components.ETComponents;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public class EnvDistributorBlockEntity extends BlockEntity {
|
||||||
|
|
||||||
|
public static final String ENV_TAG = "Env";
|
||||||
|
private final EnvStorage envStorage = new EnvStorage(EnvType.Chunk, 64) {
|
||||||
|
@Override
|
||||||
|
public void onContentsChanged() {
|
||||||
|
EnvDistributorBlockEntity.this.setChanged();
|
||||||
|
assert level != null;
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public EnvDistributorBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
||||||
|
super(ETBlockEntities.ENV_DISTRIBUTOR_BLOCK_ENTITY.get(), pPos, pBlockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadAdditional(@NotNull CompoundTag pTag, HolderLookup.@NotNull Provider pRegistries) {
|
||||||
|
super.loadAdditional(pTag, pRegistries);
|
||||||
|
CompoundTag modData = pTag.getCompound(MODID);
|
||||||
|
this.envStorage.setEnvStored(modData.getLong(ENV_TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void saveAdditional(@NotNull CompoundTag pTag, HolderLookup.@NotNull Provider pRegistries) {
|
||||||
|
super.saveAdditional(pTag, pRegistries);
|
||||||
|
CompoundTag modData = new CompoundTag();
|
||||||
|
modData.putLong(ENV_TAG, envStorage.getEnvStored());
|
||||||
|
pTag.put(MODID, modData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void serverTick(ServerLevel level, BlockPos blockPos, BlockState blockState) {
|
||||||
|
if (envStorage.getEnvStored() > 0) {
|
||||||
|
ChunkAccess chunk = level.getChunk(blockPos);
|
||||||
|
long value = Math.min(20, envStorage.getEnvStored());
|
||||||
|
chunk.setData(ETAttachments.ENV, chunk.getData(ETAttachments.ENV) + value);
|
||||||
|
envStorage.setEnvStored(envStorage.getEnvStored() - value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user