MOre work on solar panels. Blockstate json isn't ready yet.
This commit is contained in:
parent
4245decc3c
commit
b7a0854cae
22 changed files with 125 additions and 305 deletions
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.tiles.generator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.init.ModBlocks;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 25/02/2016.
|
||||
*/
|
||||
public class TileCreativeSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
||||
|
||||
boolean shouldMakePower = false;
|
||||
boolean lastTickSate = false;
|
||||
|
||||
int powerToAdd;
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
setEnergy(getMaxPower());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return 1_000_000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final EnumFacing direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final EnumFacing direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 16_192;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPowerTier getBaseTier() {
|
||||
return EnumPowerTier.INFINITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final EntityPlayer p0) {
|
||||
return new ItemStack(ModBlocks.SOLAR_PANEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleTierWithPower() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -24,9 +24,9 @@
|
|||
|
||||
package techreborn.tiles.generator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import reborncore.api.IToolDrop;
|
||||
|
@ -34,29 +34,22 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.generator.solarpanel.BlockSolarPanel;
|
||||
import techreborn.blocks.generator.solarpanel.EnumPanelType;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.TRContent.SolarPanels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
||||
|
||||
boolean canSeeSky = false;
|
||||
boolean lastSate = false;
|
||||
int powerToAdd;
|
||||
EnumPanelType panel;
|
||||
boolean lastState = false;
|
||||
SolarPanels panel;
|
||||
|
||||
//This is left here to allow the world to create a new instance of it when loading, do not remove this.
|
||||
public TileSolarPanel() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TileSolarPanel(EnumPanelType panel) {
|
||||
this.panel = panel;
|
||||
public boolean isSunOut() {
|
||||
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaytime();
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
@ -65,13 +58,12 @@ public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
|||
}
|
||||
if (world.getTotalWorldTime() % 20 == 0) {
|
||||
canSeeSky = world.canBlockSeeSky(pos.up());
|
||||
if (lastSate != isSunOut()) {
|
||||
world.setBlockState(pos,
|
||||
world.getBlockState(pos).withProperty(BlockSolarPanel.ACTIVE, isSunOut()));
|
||||
lastSate = isSunOut();
|
||||
if (lastState != isSunOut()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockSolarPanel.ACTIVE, isSunOut()));
|
||||
lastState = isSunOut();
|
||||
}
|
||||
|
||||
}
|
||||
int powerToAdd;
|
||||
if (isSunOut()) {
|
||||
powerToAdd = panel.generationRateD;
|
||||
} else if (canSeeSky) {
|
||||
|
@ -83,10 +75,6 @@ public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
|||
addEnergy(powerToAdd);
|
||||
}
|
||||
|
||||
public boolean isSunOut() {
|
||||
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaytime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return panel.internalCapacity;
|
||||
|
@ -122,44 +110,42 @@ public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
|||
return getTier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final EntityPlayer playerIn) {
|
||||
return new ItemStack(ModBlocks.SOLAR_PANEL, 1, panel.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
if (tag.hasKey("panelType")) {
|
||||
panel = EnumPanelType.values()[tag.getInteger("panelType")];
|
||||
} else {
|
||||
TechReborn.LOGGER.warn("A solar panel has failed to load from NBT, it will not work correctly. Please break and replace it to fix the issue. BlockPos:" + pos.toString());
|
||||
panel = EnumPanelType.Basic;
|
||||
}
|
||||
super.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
tag.setInteger("panelType", panel.ordinal());
|
||||
return super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTier() {
|
||||
//Nope
|
||||
// Nope
|
||||
}
|
||||
|
||||
// TODO: Translate
|
||||
@Override
|
||||
public void addInfo(List<String> info, boolean isRealTile) {
|
||||
info.add(TextFormatting.GRAY + "Internal Energy Storage: " + TextFormatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted((int) getMaxPower()));
|
||||
+ PowerSystem.getLocaliszedPowerFormatted((int) getMaxPower()));
|
||||
|
||||
info.add(TextFormatting.GRAY + "Generation Rate Day: " + TextFormatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD));
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD));
|
||||
|
||||
info.add(TextFormatting.GRAY + "Generation Rate Night: " + TextFormatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateN));
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateN));
|
||||
|
||||
info.add(TextFormatting.GRAY + "Tier: " + TextFormatting.GOLD + StringUtils.toFirstCapitalAllLowercase(getTier().toString()));
|
||||
info.add(TextFormatting.GRAY + "Tier: " + TextFormatting.GOLD
|
||||
+ StringUtils.toFirstCapitalAllLowercase(getTier().toString()));
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
Block panelBlock = world.getBlockState(pos).getBlock();
|
||||
if (panelBlock instanceof BlockSolarPanel) {
|
||||
BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock;
|
||||
panel = solarPanelBlock.panelType;
|
||||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final EntityPlayer playerIn) {
|
||||
// return new ItemStack(ModBlocks.SOLAR_PANEL, 1, panel.ordinal());
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue