Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/main/java/supersymmetry/common/blocks/BlockSolarPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package supersymmetry.common.blocks;

import gregtech.api.block.IStateHarvestLevel;
import gregtech.api.block.VariantBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

public class BlockSolarPanel extends VariantBlock<BlockSolarPanel.SolarPanelType> {

public BlockSolarPanel() {
super(net.minecraft.block.material.Material.IRON);
setTranslationKey("solar_panel");
setHardness(-1.0f);
setResistance(1000.0f);
setSoundType(SoundType.METAL);
setHarvestLevel("wrench", 10);
setDefaultState(getState(SolarPanelType.DEFAULT));
}

@Override
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
@NotNull EntityLiving.SpawnPlacementType type) {
return false;
}

@Override
public boolean isOpaqueCube(@NotNull IBlockState state) {
return false;
}

@NotNull
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.CUTOUT;
}

public enum SolarPanelType implements IStringSerializable, IStateHarvestLevel {

DEFAULT("default", 9);

private final String name;
private final int harvestLevel;

SolarPanelType(String name, int harvestLevel) {
this.name = name;
this.harvestLevel = harvestLevel;
}

@Nonnull
public String getName() {
return this.name;
}

public int getHarvestLevel(IBlockState state) {
return this.harvestLevel;
}

public String getHarvestTool(IBlockState state) {
return "wrench";
}
}
}
1 change: 1 addition & 0 deletions src/main/java/supersymmetry/common/blocks/SuSyBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class SuSyBlocks {
public static BlockGrinderCasing GRINDER_CASING;
public static BlockGirthGearTooth GIRTH_GEAR_TOOTH;
public static BlockEDMElectrode EDM_ELECTRODE;
public static BlockSolarPanel SOLAR_PANEL;

public static BlockLunarConcrete LUNAR_CONCRETE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public class SuSyMetaTileEntities {
public static MetaTileEntityIncinerator[] INCINERATOR = new MetaTileEntityIncinerator[4];

public static MetaTileEntityRTG[] RTG = new MetaTileEntityRTG[8];
public static MetaTileEntitySolarPanel[] SOLAR_PANEL = new MetaTileEntitySolarPanel[2];

public static MetaTileEntityStrandBus IMPORT_STRAND;
public static MetaTileEntityStrandBus EXPORT_STRAND;
Expand Down Expand Up @@ -570,6 +571,10 @@ public static void init() {
RTG[0] = registerMetaTileEntity(16504, new MetaTileEntityRTG(susyId("rtg.lv"), 1));
RTG[1] = registerMetaTileEntity(16505, new MetaTileEntityRTG(susyId("rtg.mv"), 2));

// Solar panels: 16512-16520
SOLAR_PANEL[0] = registerMetaTileEntity(16512, new MetaTileEntitySolarPanel(susyId("solar_panel.lv"), 1));
SOLAR_PANEL[1] = registerMetaTileEntity(16513, new MetaTileEntitySolarPanel(susyId("solar_panel.mv"), 2));

// Strand casting: 16600-16610
IMPORT_STRAND = registerMetaTileEntity(16600, new MetaTileEntityStrandBus(susyId("strand_bus.import"), false));
EXPORT_STRAND = registerMetaTileEntity(16601, new MetaTileEntityStrandBus(susyId("strand_bus.export"), true));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package supersymmetry.common.metatileentities.single.electric;

import gregtech.api.GTValues;
import gregtech.api.gui.ModularUI;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.TieredMetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import supersymmetry.api.SusyLog;
import supersymmetry.common.blocks.BlockSolarPanel;
import supersymmetry.common.blocks.SuSyBlocks;

import java.util.List;

import static gregtech.api.GTValues.LV;
import static net.minecraft.block.Block.getStateById;


public class MetaTileEntitySolarPanel extends TieredMetaTileEntity {

public MetaTileEntitySolarPanel(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, tier);
}
IBlockState panelDisplayBlock = SuSyBlocks.SOLAR_PANEL.getState(BlockSolarPanel.SolarPanelType.DEFAULT);

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity iGregTechTileEntity) {
return new MetaTileEntitySolarPanel(this.metaTileEntityId, this.getTier());
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
return null;
}

@Override
protected boolean openGUIOnRightClick() {
return false;
}

@Override
protected void reinitializeEnergyContainer() {
super.reinitializeEnergyContainer();
}

public static boolean hasSkyAccess(@NotNull World world, @NotNull BlockPos blockPos) {
BlockPos up = blockPos.up(3);
return world.canSeeSky(up);
}

public boolean hasSolarPanelDisplay(@NotNull World world, @NotNull BlockPos blockPos) {
BlockPos up = blockPos.up(2);
return world.getBlockState(up) == panelDisplayBlock;
}

public boolean panelIsNotObstructed(@NotNull World world, @NotNull BlockPos blockPos) {
BlockPos up = blockPos.up();
return world.getBlockState(up) == getStateById(0);
}

public int getNumberOfNearbyPanels(@NotNull World world, @NotNull BlockPos blockPos) {
int numPanels = 0;
BlockPos current = blockPos.north().west().up(2);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (world.getBlockState(current) == panelDisplayBlock) {
numPanels++;
}
current = current.south();
}
current = current.north(3);
current = current.east();
}
return numPanels - 1;
}

@Override
public void update() {
super.update();
World world = this.getWorld();
long time = world.getWorldTime() % 24000;
double multiplier = 0;
if (hasSkyAccess(world, this.getPos()) && hasSolarPanelDisplay(world, this.getPos()) &&
panelIsNotObstructed(world, this.getPos())) {
if (time >= 2000 && time < 10000) { //6000 is noon, 18000 is midnight
multiplier = 1;
} else if (time >= 14000 && time <= 22000) {
multiplier = 0;
} else if (time >= 10000 && time < 14000) {
multiplier = (double) (14000 - time) / 4000.0;
} else if (time < 2000) {
multiplier = (double) time / 4000.0 + 0.5;
} else {
multiplier = (double) (time - 22000) / 4000.0;
}

Biome biome = world.getBiome(this.getPos());
if (world.isRaining() && (biome.canRain() || biome.getEnableSnow())) {
multiplier = multiplier * 0.5;
}
multiplier *= Math.pow(0.5, getNumberOfNearbyPanels(world, this.getPos()));
multiplier = Math.clamp(multiplier, 0, 1);
}
this.energyContainer.changeEnergy(Math.round(GTValues.V[LV] * multiplier * ((double) getTier() / 2 + 0.5)));

}

@Override
protected boolean isEnergyEmitter() {
return true;
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, @NotNull List<String> tooltip,
boolean advanced) {
tooltip.add(I18n.format("susy.machine.solar_panel.tooltip.info"));
tooltip.add(I18n.format("susy.machine.solar_panel.tooltip.description1"));
tooltip.add(I18n.format("susy.machine.solar_panel.tooltip.description2"));
tooltip.add(I18n.format("susy.machine.solar_panel.tooltip.description3"));
tooltip.add(I18n.format("susy.machine.solar_panel.voltage_produced",
new Object[] { (Math.toIntExact(Math.round(GTValues.V[LV] * ((double) getTier() / 2 + 0.5)))), GTValues.VNF[this.getTier()] }));
tooltip.add(I18n.format("gregtech.universal.tooltip.max_voltage_out",
new Object[] { this.energyContainer.getOutputVoltage(), GTValues.VNF[this.getTier()] }));
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity",
new Object[] { this.energyContainer.getEnergyCapacity() }));
}

@Override
public boolean getIsWeatherOrTerrainResistant() {
return true;
}

@Override
public void onPlacement() {
World world = this.getWorld();
super.onPlacement();
if (world.getBlockState(this.getPos().up(2)) == getStateById(0)) {
world.setBlockState(this.getPos().up(2), panelDisplayBlock);
}
}

@Override
public void onRemoval() {
World world = this.getWorld();
super.onRemoval();
if (world.getBlockState(this.getPos().up(2)) == panelDisplayBlock) {
world.setBlockState(this.getPos().up(2), getStateById(0));
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/main/resources/assets/susy/blockstates/solar_panel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"forge_marker" : 1,
"variants" : {
"variant=default": { "model": "susy:solar_panel/default" }
}
}
10 changes: 10 additions & 0 deletions src/main/resources/assets/susy/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,16 @@ susy.machine.component_scanner.pos=Error found at %s

susy.machine.building_cleanroom.name=Spacecraft Component Cleanroom

# Solar panels
susy.machine.solar_panel.lv.name=Monocrystalline Silicon Solar Panel
susy.machine.solar_panel.mv.name=Multi-Junction Solar Panel
susy.machine.solar_panel.tooltip.info=May the Sun be with you.
susy.machine.solar_panel.tooltip.description1=Generates power during daylight hours, rising/falling gradually during dawn and dusk.
susy.machine.solar_panel.tooltip.description2=Production reduced by 50%% when raining and for every solar panel in the surrounding 8 blocks.
susy.machine.solar_panel.tooltip.description3=Ensure the block above the panel base is clear!
susy.machine.solar_panel.voltage_produced=§aPeak Production: §f%,d EU/t (%s§f)
tile.solar_panel.default.name=Solar Panel Display Block

# Recipemaps
recipemap.coagulation_tank.name=Coagulation
recipemap.latex_collector.name=Arboreal Collector
Expand Down
Loading
Loading