Solar Panel re-implementation
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package me.hypherionmc.hyperlighting.common.blockentities;
|
||||
|
||||
import me.hypherionmc.craterlib.api.blockentities.ITickable;
|
||||
import me.hypherionmc.craterlib.api.blockentities.caps.ForgeCapability;
|
||||
import me.hypherionmc.craterlib.common.blockentity.CraterBlockEntity;
|
||||
import me.hypherionmc.craterlib.systems.energy.CustomEnergyStorage;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.SolarPanel;
|
||||
import me.hypherionmc.hyperlighting.common.init.HLBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 18/09/2022
|
||||
*/
|
||||
public class SolarPanelBlockEntity extends CraterBlockEntity implements ITickable {
|
||||
|
||||
private CustomEnergyStorage energyStorage = new CustomEnergyStorage(2000, 50, 1000);
|
||||
|
||||
public SolarPanelBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(HLBlockEntities.SOLAR_PANEL.get(), pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Level level, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity) {
|
||||
if (this.getBlockState().getBlock() instanceof SolarPanel && level.isDay() && level.canSeeSky(blockPos)) {
|
||||
int i = level.getBrightness(LightLayer.SKY, blockPos) - level.getSkyDarken();
|
||||
float f = level.getSunAngle(1.0F);
|
||||
|
||||
if (i > 8 && this.energyStorage.getPowerLevel() < this.energyStorage.getPowerCapacity()) {
|
||||
float f1 = f < (float) Math.PI ? 0.0F : ((float) Math.PI * 2F);
|
||||
f = f + (f1 - f) * 0.2F;
|
||||
i = Math.round((float) i * Mth.cos(f));
|
||||
i = Mth.clamp(i, 0, 15);
|
||||
this.energyStorage.receiveEnergyInternal(i, false);
|
||||
}
|
||||
this.sendUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
this.energyStorage.readNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
this.energyStorage.writeNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getForgeCapability(ForgeCapability forgeCapability, Direction direction) {
|
||||
if (forgeCapability == ForgeCapability.ENERGY && (direction == Direction.DOWN || direction == null)) {
|
||||
return (Optional<T>) Optional.of(energyStorage);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package me.hypherionmc.hyperlighting.common.blocks;
|
||||
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.SolarPanelBlockEntity;
|
||||
import me.hypherionmc.hyperlighting.common.init.CommonRegistration;
|
||||
import me.hypherionmc.hyperlighting.common.init.HLItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
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.material.Material;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 18/09/2022
|
||||
*/
|
||||
public class SolarPanel extends BaseEntityBlock {
|
||||
|
||||
private final VoxelShape BOUNDS = Block.box(0, 0, 0, 16, 1.92, 16);
|
||||
|
||||
public SolarPanel(String name) {
|
||||
super(Properties.of(Material.GLASS).sound(SoundType.GLASS).noCollission().noOcclusion());
|
||||
|
||||
HLItems.register(name, () -> new BlockItem(this, new Item.Properties().tab(CommonRegistration.MACHINES_TAB)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext context) {
|
||||
return BOUNDS;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
|
||||
return (level1, blockPos, blockState1, t) -> {
|
||||
if (!level1.isClientSide() && t instanceof SolarPanelBlockEntity be) {
|
||||
be.tick(level1, blockPos, blockState1, be);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return new SolarPanelBlockEntity(blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
}
|
@@ -12,6 +12,8 @@ public class CommonRegistration {
|
||||
|
||||
public static HyperLightingClientConfig config = new HyperLightingClientConfig();
|
||||
public static final CreativeModeTab LIGHTS_TAB = CreativeTabBuilder.builder(MOD_ID, "lighting").setIcon(() -> new ItemStack(HLBlocks.ADVANCED_LANTERN)).build();
|
||||
public static final CreativeModeTab MACHINES_TAB = CreativeTabBuilder.builder(MOD_ID, "machines").setIcon(() -> new ItemStack(HLBlocks.ADVANCED_TORCH)).build();
|
||||
|
||||
|
||||
public static void registerAll() {
|
||||
HLSounds.loadAll();
|
||||
|
@@ -4,6 +4,7 @@ import me.hypherionmc.craterlib.systems.reg.RegistrationProvider;
|
||||
import me.hypherionmc.craterlib.systems.reg.RegistryObject;
|
||||
import me.hypherionmc.hyperlighting.Constants;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.AdvancedCampfireBlockEntity;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.SolarPanelBlockEntity;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
@@ -17,5 +18,7 @@ public class HLBlockEntities {
|
||||
|
||||
public static RegistryObject<BlockEntityType<AdvancedCampfireBlockEntity>> CAMPFIRE = BE.register("campfire", () -> BlockEntityType.Builder.of(AdvancedCampfireBlockEntity::new, HLBlocks.ADVANCED_CAMPFIRE.get()).build(null));
|
||||
|
||||
public static RegistryObject<BlockEntityType<SolarPanelBlockEntity>> SOLAR_PANEL = BE.register("solar_panel", () -> BlockEntityType.Builder.of(SolarPanelBlockEntity::new, HLBlocks.SOLAR_PANEL.get()).build(null));
|
||||
|
||||
public static void loadAll() {}
|
||||
}
|
||||
|
@@ -3,10 +3,7 @@ package me.hypherionmc.hyperlighting.common.init;
|
||||
import me.hypherionmc.craterlib.systems.reg.BlockRegistryObject;
|
||||
import me.hypherionmc.craterlib.systems.reg.RegistrationProvider;
|
||||
import me.hypherionmc.hyperlighting.Constants;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.AdvancedCandleBlock;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.AdvancedCampfire;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.AdvancedLanternBlock;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.AdvancedTorchBlock;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -30,6 +27,10 @@ public class HLBlocks {
|
||||
/* Candles */
|
||||
public static BlockRegistryObject<Block> ADVANCED_CANDLE = register("advanced_candle", () -> new AdvancedCandleBlock("advanced_candle", DyeColor.ORANGE, CommonRegistration.LIGHTS_TAB));
|
||||
|
||||
/* Machines */
|
||||
public static BlockRegistryObject<Block> SOLAR_PANEL = register("solar_panel", () -> new SolarPanel("solar_panel"));
|
||||
|
||||
|
||||
public static void loadAll() {}
|
||||
|
||||
public static <B extends Block> BlockRegistryObject<B> register(String name, Supplier<? extends B> block) {
|
||||
|
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"variants": {
|
||||
"": { "model": "hyperlighting:block/solar_panel" }
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"credit": "Made with Blockbench",
|
||||
"texture_size": [16, 32],
|
||||
"textures": {
|
||||
"0": "hyperlighting:block/solar",
|
||||
"particle": "hyperlighting:block/solar"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [0, 0, 0],
|
||||
"to": [16, 2, 16],
|
||||
"faces": {
|
||||
"north": {"uv": [0, 8, 16, 10], "texture": "#0"},
|
||||
"east": {"uv": [0, 8, 16, 10], "texture": "#0"},
|
||||
"south": {"uv": [0, 8, 16, 10], "texture": "#0"},
|
||||
"west": {"uv": [0, 8, 16, 10], "texture": "#0"},
|
||||
"up": {"uv": [0, 0, 16, 8], "texture": "#0"},
|
||||
"down": {"uv": [0, 8, 16, 16], "texture": "#0"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "hyperlighting:block/solar_panel"
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 781 B |
@@ -0,0 +1,21 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.wthit.dataproviders;
|
||||
|
||||
import mcp.mobius.waila.api.IPluginConfig;
|
||||
import mcp.mobius.waila.api.IServerAccessor;
|
||||
import mcp.mobius.waila.api.IServerDataProvider;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.SolarPanelBlockEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 18/09/2022
|
||||
*/
|
||||
public class SolarPanelDataProvider implements IServerDataProvider<SolarPanelBlockEntity> {
|
||||
|
||||
@Override
|
||||
public void appendServerData(CompoundTag data, IServerAccessor<SolarPanelBlockEntity> accessor, IPluginConfig config) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
accessor.getTarget().saveAdditional(tag);
|
||||
data.put("hl_solar", tag);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.wthit.providers;
|
||||
|
||||
import mcp.mobius.waila.api.IBlockAccessor;
|
||||
import mcp.mobius.waila.api.IBlockComponentProvider;
|
||||
import mcp.mobius.waila.api.IPluginConfig;
|
||||
import mcp.mobius.waila.api.ITooltip;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 18/09/2022
|
||||
*/
|
||||
public class SolarPanelProvider implements IBlockComponentProvider {
|
||||
|
||||
@Override
|
||||
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
|
||||
CompoundTag compound = accessor.getServerData().getCompound("hl_solar");
|
||||
int powerLevel = compound.getInt("powerLevel");
|
||||
int level = (int) (((float) powerLevel / 2000) * 100);
|
||||
tooltip.addLine(Component.literal("Power Level : " + ChatFormatting.YELLOW + level + "%"));
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
#dependencies
|
||||
craterlib_version=0.0.2d
|
||||
craterlib_version=0.0.3d
|
||||
mod_menu_version=4.0.6
|
||||
shimmer_version=0.1.12
|
||||
sodium_version=3957319
|
||||
|
Reference in New Issue
Block a user