Some work on solar panels flattening

This commit is contained in:
drcrazy 2018-09-18 15:32:13 +03:00
parent 0918bceb23
commit 4245decc3c
5 changed files with 33 additions and 212 deletions

View file

@ -1,97 +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.blocks.generator;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import reborncore.api.ToolManager;
import reborncore.client.models.ModelCompound;
import reborncore.client.models.RebornModelRegistry;
import reborncore.common.BaseTileBlock;
import reborncore.common.RebornCoreConfig;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.items.WrenchHelper;
import techreborn.TechReborn;
import techreborn.init.ModBlocks;
import techreborn.tiles.generator.TileCreativeSolarPanel;
import techreborn.utils.TechRebornCreativeTab;
/**
* Created by modmuss50 on 25/02/2016.
*/
public class BlockCreativeSolarPanel extends BaseTileBlock {
public BlockCreativeSolarPanel() {
super(Material.IRON);
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(2.0F);
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/generators"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos);
// We extended BaseTileBlock. Thus we should always have tile entity. I hope.
if (tileEntity == null) {
return false;
}
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
if (WrenchHelper.handleWrench(stack, worldIn, pos, playerIn, side)) {
return true;
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
if (RebornCoreConfig.wrenchRequired) {
drops.add(new ItemStack(ModBlocks.MACHINE_BLOCK_ADVANCED));
} else {
super.getDrops(drops, world, pos, state, fortune);
}
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileCreativeSolarPanel();
}
}

View file

@ -24,95 +24,30 @@
package techreborn.blocks.generator.solarpanel;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.client.models.ModelCompound;
import reborncore.client.models.RebornModelRegistry;
import reborncore.common.blocks.BlockMachineBase;
import techreborn.TechReborn;
import techreborn.tiles.generator.TileSolarPanel;
import techreborn.utils.TechRebornCreativeTab;
/**
* Created by modmuss50 on 25/02/2016.
*/
public class BlockSolarPanel extends BlockMachineBase {
public static final String[] panes = new String[] {
"basic", "hybrid", "advanced", "ultimate", "quantum"};
public static PropertyBool ACTIVE = PropertyBool.create("active");
public static final IProperty<EnumPanelType> TYPE = PropertyEnum.create("type", EnumPanelType.class);
public BlockSolarPanel() {
super(true);
super();
setCreativeTab(TechRebornCreativeTab.instance);
this.setDefaultState(this.getBlockState().getBaseState().withProperty(ACTIVE, false).withProperty(TYPE, EnumPanelType.Basic));
for (int i = 0; i < panes.length; i++) {
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, i, "machines/generators").setInvVariant("active=false,type=" + panes[i]));
}
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/generators"));
}
@Override
public int getMetaFromState(IBlockState state) {
int active = state.getValue(ACTIVE) ? EnumPanelType.values().length : 0;
return state.getValue(TYPE).ordinal() + active;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, ACTIVE, TYPE);
}
@Override
public IBlockState getStateFromMeta(int meta) {
boolean active = false;
if(meta >= EnumPanelType.values().length){
active = true;
meta -= EnumPanelType.values().length;
}
return getDefaultState().withProperty(ACTIVE, active).withProperty(TYPE, EnumPanelType.values()[meta]);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileSolarPanel(getStateFromMeta(meta).getValue(TYPE));
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return getStateFromMeta(placer.getHeldItem(hand).getItemDamage());
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
//return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
return new ItemStack(Item.getItemFromBlock(this), 1, world.getBlockState(pos).getValue(TYPE).ordinal());
}
@Override
public int damageDropped(IBlockState state) {
return state.getValue(TYPE).ordinal();
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
for (EnumPanelType panelType : EnumPanelType.values()) {
list.add(new ItemStack(this, 1, panelType.ordinal()));
}
public TileEntity createNewTileEntity(final World world, final int meta) {
// TODO: FIx me
return null;
}
@Override

View file

@ -34,7 +34,8 @@ public enum EnumPanelType implements IStringSerializable {
Hybrid("hybrid", EnumPowerTier.LOW),
Advanced("advanced", EnumPowerTier.MEDIUM),
Ultimate("ultimate", EnumPowerTier.HIGH),
Quantum("quantum", EnumPowerTier.EXTREME);
Quantum("quantum", EnumPowerTier.EXTREME),
CREATIVE("creative", EnumPowerTier.EXTREME);
private String friendlyName;
// Generation of EU during Day
@ -48,6 +49,7 @@ public enum EnumPanelType implements IStringSerializable {
EnumPanelType(String friendlyName, EnumPowerTier tier) {
this.friendlyName = friendlyName;
this.powerTier = tier;
// TODO: Fix me
switch (friendlyName) {
case "basic":
this.generationRateD = ConfigTechReborn.basicGenerationRateD;