From d9d8845d6d756dc54404f34eafd35904ceb1e5a0 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 6 Nov 2016 19:14:43 +0000 Subject: [PATCH] Added flare, still needs some textures --- .../java/techreborn/blocks/BlockFlare.java | 102 ++++++++++++++++++ .../client/particle/ParticleSmoke.java | 11 ++ src/main/java/techreborn/init/ModBlocks.java | 12 +++ .../techreborn/tiles/TileEntityFlare.java | 40 +++++++ 4 files changed, 165 insertions(+) create mode 100644 src/main/java/techreborn/blocks/BlockFlare.java create mode 100644 src/main/java/techreborn/client/particle/ParticleSmoke.java create mode 100644 src/main/java/techreborn/tiles/TileEntityFlare.java diff --git a/src/main/java/techreborn/blocks/BlockFlare.java b/src/main/java/techreborn/blocks/BlockFlare.java new file mode 100644 index 000000000..e6c15e2dc --- /dev/null +++ b/src/main/java/techreborn/blocks/BlockFlare.java @@ -0,0 +1,102 @@ +package techreborn.blocks; + +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +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.Entity; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import techreborn.client.TechRebornCreativeTabMisc; +import techreborn.tiles.TileEntityFlare; + +import javax.annotation.Nullable; +import java.util.List; + +/** + * Created by modmuss50 on 06/11/2016. + */ +public class BlockFlare extends BlockContainer { + + public static final AxisAlignedBB FLARE_BB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.1D, 1.0D); + + public static final PropertyEnum COLOR = PropertyEnum.create("color", EnumDyeColor.class); + + public BlockFlare() { + super(Material.REDSTONE_LIGHT); + setCreativeTab(TechRebornCreativeTabMisc.instance); + setUnlocalizedName("techreborn.flare"); + this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE)); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + if (worldIn.isRemote) { //Only needed on the client + return new TileEntityFlare(); + } + return null; + } + + public int damageDropped(IBlockState state) { + return (state.getValue(COLOR)).getMetadata(); + } + + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + for (EnumDyeColor enumdyecolor : EnumDyeColor.values()) { + list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata())); + } + } + + public MapColor getMapColor(IBlockState state) { + return (state.getValue(COLOR)).getMapColor(); + } + + public IBlockState getStateFromMeta(int meta) { + return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta)); + } + + public int getMetaFromState(IBlockState state) { + return (state.getValue(COLOR)).getMetadata(); + } + + protected BlockStateContainer createBlockState() { + return new BlockStateContainer(this, COLOR); + } + + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.CUTOUT; + } + + public boolean isFullCube() { + return false; + } + + @Override + public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) { + return FLARE_BB; + } + + @Override + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { + return FLARE_BB; + } +} diff --git a/src/main/java/techreborn/client/particle/ParticleSmoke.java b/src/main/java/techreborn/client/particle/ParticleSmoke.java new file mode 100644 index 000000000..ccc2ab980 --- /dev/null +++ b/src/main/java/techreborn/client/particle/ParticleSmoke.java @@ -0,0 +1,11 @@ +package techreborn.client.particle; + +import net.minecraft.client.particle.ParticleSmokeLarge; +import net.minecraft.world.World; + +public class ParticleSmoke extends ParticleSmokeLarge { + + public ParticleSmoke(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double p_i1201_8_, double p_i1201_10_, double p_i1201_12_) { + super(worldIn, xCoordIn, yCoordIn, zCoordIn, p_i1201_8_, p_i1201_10_, p_i1201_12_); + } +} diff --git a/src/main/java/techreborn/init/ModBlocks.java b/src/main/java/techreborn/init/ModBlocks.java index 92b47b624..32306981e 100644 --- a/src/main/java/techreborn/init/ModBlocks.java +++ b/src/main/java/techreborn/init/ModBlocks.java @@ -1,9 +1,11 @@ package techreborn.init; import net.minecraft.block.Block; +import net.minecraft.block.BlockColored; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemColored; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.oredict.OreDictionary; @@ -21,6 +23,7 @@ import techreborn.blocks.tier1.*; import techreborn.blocks.transformers.BlockHVTransformer; import techreborn.blocks.transformers.BlockLVTransformer; import techreborn.blocks.transformers.BlockMVTransformer; +import techreborn.client.TechRebornCreativeTabMisc; import techreborn.itemblocks.*; import techreborn.tiles.*; import techreborn.tiles.fusionReactor.TileEntityFusionController; @@ -114,6 +117,7 @@ public class ModBlocks { public static Block rubberPlanks; public static Block ironFence; + public static Block flare; public static void init() { thermalGenerator = new BlockThermalGenerator(); @@ -379,6 +383,14 @@ public class ModBlocks { registerBlock(scrapboxinator, "scrapboxinator"); GameRegistry.registerTileEntity(TileScrapboxinator.class, "TileScrapboxinatorTR"); + flare = new BlockFlare(); + registerBlock(flare, "flare"); + ItemBlock itemBlock = new ItemColored(flare, true); + itemBlock.setRegistryName("flareItemBlock"); + itemBlock.setCreativeTab(TechRebornCreativeTabMisc.instance); + GameRegistry.register(itemBlock); + GameRegistry.registerTileEntity(TileEntityFlare.class, "TileEntityFlareTR"); + registerOreDict(); Core.logHelper.info("TechReborns Blocks Loaded"); } diff --git a/src/main/java/techreborn/tiles/TileEntityFlare.java b/src/main/java/techreborn/tiles/TileEntityFlare.java new file mode 100644 index 000000000..d820e00fa --- /dev/null +++ b/src/main/java/techreborn/tiles/TileEntityFlare.java @@ -0,0 +1,40 @@ +package techreborn.tiles; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.ITickable; +import techreborn.blocks.BlockFlare; +import techreborn.client.particle.ParticleSmoke; + +import java.util.Random; + +/** + * Created by modmuss50 on 06/11/2016. + */ +public class TileEntityFlare extends TileEntity implements ITickable { + + Random random = new Random(); + + @Override + public void update() { + EnumDyeColor color = worldObj.getBlockState(pos).getValue(BlockFlare.COLOR); + if(worldObj.isRemote && worldObj.isAirBlock(getPos().up())){ + ParticleSmoke particleSmokeLarge = new ParticleSmoke(worldObj , pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0.0D, 0); + particleSmokeLarge.setMaxAge(250); + if(color != EnumDyeColor.WHITE){ + float[] rgb = EntitySheep.getDyeRgb(color); + particleSmokeLarge.setRBGColorF(rgb[0] + (random.nextFloat() /20), rgb[1] + (random.nextFloat() /20), rgb[2] + (random.nextFloat() /20)); + } + particleSmokeLarge.multipleParticleScaleBy(0.5F); + + Minecraft.getMinecraft().effectRenderer.addEffect(particleSmokeLarge); + + worldObj.spawnParticle(EnumParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 0.3, pos.getZ() + 0.5, 0.0D, 0.0D, 0.0D); + } + } + + +}