From bf4a76431ec4dd56031b90f8e34a11513eb4a507 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 27 Apr 2020 18:30:44 +0200 Subject: [PATCH] light staff, part 1 --- .../assets/naturesaura/blockstates/light.json | 7 ++ .../naturesaura/models/block/light.json | 6 ++ .../naturesaura/models/item/light_staff.json | 6 ++ .../models/item/potted_aura_bloom.json | 3 - .../models/item/potted_aura_cactus.json | 3 - .../naturesaura/loot_tables/blocks/light.json | 19 +++++ .../naturesaura/blocks/BlockLight.java | 62 +++++++++++++++++ .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../naturesaura/data/ItemModelGenerator.java | 3 +- .../entities/EntityLightProjectile.java | 65 ++++++++++++++++++ .../naturesaura/entities/ModEntities.java | 1 + .../entities/render/RenderStub.java | 24 +++++++ .../naturesaura/items/ItemLightStaff.java | 28 ++++++++ .../ellpeck/naturesaura/items/ModItems.java | 1 + .../ellpeck/naturesaura/reg/ModRegistry.java | 15 +++- .../naturesaura/textures/block/light.png | Bin 0 -> 91 bytes .../naturesaura/textures/item/light_staff.png | Bin 0 -> 441 bytes 17 files changed, 234 insertions(+), 10 deletions(-) create mode 100644 src/generated/resources/assets/naturesaura/blockstates/light.json create mode 100644 src/generated/resources/assets/naturesaura/models/block/light.json create mode 100644 src/generated/resources/assets/naturesaura/models/item/light_staff.json delete mode 100644 src/generated/resources/assets/naturesaura/models/item/potted_aura_bloom.json delete mode 100644 src/generated/resources/assets/naturesaura/models/item/potted_aura_cactus.json create mode 100644 src/generated/resources/data/naturesaura/loot_tables/blocks/light.json create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockLight.java create mode 100644 src/main/java/de/ellpeck/naturesaura/entities/EntityLightProjectile.java create mode 100644 src/main/java/de/ellpeck/naturesaura/entities/render/RenderStub.java create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemLightStaff.java create mode 100644 src/main/resources/assets/naturesaura/textures/block/light.png create mode 100644 src/main/resources/assets/naturesaura/textures/item/light_staff.png diff --git a/src/generated/resources/assets/naturesaura/blockstates/light.json b/src/generated/resources/assets/naturesaura/blockstates/light.json new file mode 100644 index 00000000..96d67e7f --- /dev/null +++ b/src/generated/resources/assets/naturesaura/blockstates/light.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "naturesaura:block/light" + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/block/light.json b/src/generated/resources/assets/naturesaura/models/block/light.json new file mode 100644 index 00000000..d6918522 --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/block/light.json @@ -0,0 +1,6 @@ +{ + "parent": "block/air", + "textures": { + "particle": "naturesaura:block/light" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/item/light_staff.json b/src/generated/resources/assets/naturesaura/models/item/light_staff.json new file mode 100644 index 00000000..6e4a66de --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/item/light_staff.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:item/light_staff" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/item/potted_aura_bloom.json b/src/generated/resources/assets/naturesaura/models/item/potted_aura_bloom.json deleted file mode 100644 index 0290f89f..00000000 --- a/src/generated/resources/assets/naturesaura/models/item/potted_aura_bloom.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "naturesaura:block/potted_aura_bloom" -} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/item/potted_aura_cactus.json b/src/generated/resources/assets/naturesaura/models/item/potted_aura_cactus.json deleted file mode 100644 index 86e7aceb..00000000 --- a/src/generated/resources/assets/naturesaura/models/item/potted_aura_cactus.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "naturesaura:block/potted_aura_cactus" -} \ No newline at end of file diff --git a/src/generated/resources/data/naturesaura/loot_tables/blocks/light.json b/src/generated/resources/data/naturesaura/loot_tables/blocks/light.json new file mode 100644 index 00000000..78793172 --- /dev/null +++ b/src/generated/resources/data/naturesaura/loot_tables/blocks/light.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:air" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockLight.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockLight.java new file mode 100644 index 00000000..ea1e1ebf --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockLight.java @@ -0,0 +1,62 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.data.BlockStateGenerator; +import de.ellpeck.naturesaura.reg.ICustomBlockState; +import de.ellpeck.naturesaura.reg.ICustomRenderType; +import de.ellpeck.naturesaura.reg.INoItemBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +import java.util.Random; +import java.util.function.Supplier; + +public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemBlock, ICustomRenderType { + + private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12); + + public BlockLight() { + super("light", Properties.create(Material.WOOL).doesNotBlockMovement().lightValue(15)); + } + + @Override + @OnlyIn(Dist.CLIENT) + public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) { + for (int i = 0; i < 2; i++) + NaturesAuraAPI.instance().spawnMagicParticle( + pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, + rand.nextGaussian() * 0.015F, 0, rand.nextGaussian() * 0.015F, + 0xffcb5c, rand.nextFloat() * 2 + 1, 50, -0.015F, true, true); + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return SHAPE; + } + + @Override + public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) { + return true; + } + + @Override + public void generateCustomBlockState(BlockStateGenerator generator) { + generator.simpleBlock(this, generator.models().withExistingParent("light", generator.mcLoc("block/air")) + .texture("particle", "block/light")); + } + + @Override + public Supplier getRenderType() { + return RenderType::cutout; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index 9cccd994..01d36709 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -67,6 +67,7 @@ public final class ModBlocks { public static Block AURA_CACTUS; public static Block TAINTED_GOLD_BLOCK; public static Block NETHER_GRASS; + public static Block LIGHT; public static Block.Properties prop(Material material, MaterialColor color) { return Block.Properties.create(material, color); diff --git a/src/main/java/de/ellpeck/naturesaura/data/ItemModelGenerator.java b/src/main/java/de/ellpeck/naturesaura/data/ItemModelGenerator.java index 8912f27c..43317cd6 100644 --- a/src/main/java/de/ellpeck/naturesaura/data/ItemModelGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/data/ItemModelGenerator.java @@ -3,6 +3,7 @@ package de.ellpeck.naturesaura.data; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.IModItem; +import de.ellpeck.naturesaura.reg.INoItemBlock; import de.ellpeck.naturesaura.reg.ModRegistry; import net.minecraft.block.Block; import net.minecraft.data.DataGenerator; @@ -23,7 +24,7 @@ public class ItemModelGenerator extends ItemModelProvider { ((ICustomItemModel) modItem).generateCustomItemModel(this); } else if (modItem instanceof Item) { this.withExistingParent(name, "item/generated").texture("layer0", "item/" + name); - } else if (modItem instanceof Block) { + } else if (modItem instanceof Block && !(modItem instanceof INoItemBlock)) { this.withExistingParent(name, this.modLoc("block/" + name)); } } diff --git a/src/main/java/de/ellpeck/naturesaura/entities/EntityLightProjectile.java b/src/main/java/de/ellpeck/naturesaura/entities/EntityLightProjectile.java new file mode 100644 index 00000000..533b12ab --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/entities/EntityLightProjectile.java @@ -0,0 +1,65 @@ +package de.ellpeck.naturesaura.entities; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.blocks.ModBlocks; +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.projectile.ThrowableEntity; +import net.minecraft.network.IPacket; +import net.minecraft.util.math.*; +import net.minecraft.world.World; +import net.minecraftforge.fml.network.NetworkHooks; + +public class EntityLightProjectile extends ThrowableEntity { + public EntityLightProjectile(EntityType type, World worldIn) { + super(type, worldIn); + } + + public EntityLightProjectile(EntityType type, LivingEntity livingEntityIn, World worldIn) { + super(type, livingEntityIn, worldIn); + } + + @Override + public void tick() { + super.tick(); + if (this.world.isRemote && this.ticksExisted > 1) { + for (float i = 0; i <= 1; i += 0.2F) { + NaturesAuraAPI.instance().spawnMagicParticle( + MathHelper.lerp(i, this.prevPosX, this.getPosX()), + MathHelper.lerp(i, this.prevPosY, this.getPosY()), + MathHelper.lerp(i, this.prevPosZ, this.getPosZ()), + this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, + 0xffcb5c, this.rand.nextFloat() * 0.5F + 1, 20, 0, false, true); + } + } + } + + @Override + protected void onImpact(RayTraceResult result) { + if (!this.world.isRemote) { + if (result instanceof BlockRayTraceResult) { + BlockRayTraceResult res = (BlockRayTraceResult) result; + BlockPos pos = res.getPos().offset(res.getFace()); + BlockState state = this.world.getBlockState(pos); + if (state.getMaterial().isReplaceable()) + this.world.setBlockState(pos, ModBlocks.LIGHT.getDefaultState()); + } else if (result instanceof EntityRayTraceResult) { + Entity entity = ((EntityRayTraceResult) result).getEntity(); + entity.setFire(5); + } + } + this.remove(); + } + + @Override + protected void registerData() { + + } + + @Override + public IPacket createSpawnPacket() { + return NetworkHooks.getEntitySpawningPacket(this); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/entities/ModEntities.java b/src/main/java/de/ellpeck/naturesaura/entities/ModEntities.java index 54be89bb..61945b48 100644 --- a/src/main/java/de/ellpeck/naturesaura/entities/ModEntities.java +++ b/src/main/java/de/ellpeck/naturesaura/entities/ModEntities.java @@ -6,4 +6,5 @@ import net.minecraft.entity.EntityType; public final class ModEntities { public static EntityType MOVER_CART; public static EntityType EFFECT_INHIBITOR; + public static EntityType LIGHT_PROJECTILE; } diff --git a/src/main/java/de/ellpeck/naturesaura/entities/render/RenderStub.java b/src/main/java/de/ellpeck/naturesaura/entities/render/RenderStub.java new file mode 100644 index 00000000..394d8bdb --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/entities/render/RenderStub.java @@ -0,0 +1,24 @@ +package de.ellpeck.naturesaura.entities.render; + +import net.minecraft.client.renderer.culling.ClippingHelperImpl; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; + +public class RenderStub extends EntityRenderer { + public RenderStub(EntityRendererManager renderManager) { + super(renderManager); + } + + @Override + public boolean shouldRender(Entity livingEntityIn, ClippingHelperImpl camera, double camX, double camY, double camZ) { + return false; + } + + @Override + public ResourceLocation getEntityTexture(Entity entity) { + return AtlasTexture.LOCATION_BLOCKS_TEXTURE; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemLightStaff.java b/src/main/java/de/ellpeck/naturesaura/items/ItemLightStaff.java new file mode 100644 index 00000000..170cc366 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemLightStaff.java @@ -0,0 +1,28 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.entities.EntityLightProjectile; +import de.ellpeck.naturesaura.entities.ModEntities; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; +import net.minecraft.world.World; + +public class ItemLightStaff extends ItemImpl { + public ItemLightStaff() { + super("light_staff"); + } + + @Override + public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (!worldIn.isRemote && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 1000, false)) { + EntityLightProjectile projectile = new EntityLightProjectile(ModEntities.LIGHT_PROJECTILE, playerIn, worldIn); + projectile.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0, 1.5F, 0); + worldIn.addEntity(projectile); + } + return new ActionResult<>(ActionResultType.SUCCESS, stack); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index 865bfbf0..f4f99c20 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -48,4 +48,5 @@ public final class ModItems { public static Item DEATH_RING; public static Item TAINTED_GOLD; public static Item LOOT_FINDER; + public static Item LIGHT_STAFF; } diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index da294e6e..418759cd 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -12,10 +12,12 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityEnderCrate; import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment; import de.ellpeck.naturesaura.enchant.ModEnchantments; import de.ellpeck.naturesaura.entities.EntityEffectInhibitor; +import de.ellpeck.naturesaura.entities.EntityLightProjectile; import de.ellpeck.naturesaura.entities.EntityMoverMinecart; import de.ellpeck.naturesaura.entities.ModEntities; import de.ellpeck.naturesaura.entities.render.RenderEffectInhibitor; import de.ellpeck.naturesaura.entities.render.RenderMoverMinecart; +import de.ellpeck.naturesaura.entities.render.RenderStub; import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gen.WorldGenAncientTree; import de.ellpeck.naturesaura.gen.WorldGenAuraBloom; @@ -131,7 +133,8 @@ public final class ModRegistry { temp = new BlockAuraBloom("aura_cactus", TileEntityAuraCactus::new), createFlowerPot(temp), new BlockImpl("tainted_gold_block", ModBlocks.prop(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(3F)), - new BlockNetherGrass() + new BlockNetherGrass(), + new BlockLight() ); if (ModConfig.instance.rfConverter.get()) @@ -197,7 +200,8 @@ public final class ModRegistry { new ItemCrimsonMeal(), new ItemDeathRing(), new ItemImpl("tainted_gold"), - new ItemLootFinder() + new ItemLootFinder(), + new ItemLightStaff() ); Helper.populateObjectHolders(ModItems.class, event.getRegistry()); } @@ -254,12 +258,17 @@ public final class ModRegistry { EntityType.Builder.create(EntityEffectInhibitor::new, EntityClassification.MISC) .size(1, 1).setShouldReceiveVelocityUpdates(true) .setTrackingRange(64).setUpdateInterval(20).immuneToFire().build(NaturesAura.MOD_ID + ":effect_inhibitor") - .setRegistryName("effect_inhibitor") + .setRegistryName("effect_inhibitor"), + EntityType.Builder.create(EntityLightProjectile::new, EntityClassification.MISC) + .size(0.5F, 0.5F).setShouldReceiveVelocityUpdates(true) + .setTrackingRange(64).setUpdateInterval(3).immuneToFire().build(NaturesAura.MOD_ID + ":light_projectile") + .setRegistryName("light_projectile") ); Helper.populateObjectHolders(ModEntities.class, event.getRegistry()); NaturesAura.proxy.registerEntityRenderer(ModEntities.MOVER_CART, () -> RenderMoverMinecart::new); NaturesAura.proxy.registerEntityRenderer(ModEntities.EFFECT_INHIBITOR, () -> RenderEffectInhibitor::new); + NaturesAura.proxy.registerEntityRenderer(ModEntities.LIGHT_PROJECTILE, () -> RenderStub::new); } @SubscribeEvent diff --git a/src/main/resources/assets/naturesaura/textures/block/light.png b/src/main/resources/assets/naturesaura/textures/block/light.png new file mode 100644 index 0000000000000000000000000000000000000000..926ed235f2a33e69e53e579aafefe7d76b7860cb GIT binary patch literal 91 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`)Ym%P6qOYJY5_^ lEP9g@Bv=Px$b4f%&R5*>LkugXDaTLbClNtoQ(#b(gq$`~65h9uB=)r&Z!~1^U_ud0`sA;oAc7Mkj)Cy!4 z4r&E*1eu%6AokzM9RON#l3H@oAmZ%A(`Jdnxhls*2`PfjW{ua`7RN#q;arv5vjZrq zik6(DlcPiUe13S`E&zUDwuPdq&IwrTgcO0t?ZU_B7rOlkE^b~pmeAz{kRSK4*{m&M zmQV+Hy;?eDV*O_VCS>A#G)4EBGMxoaEvNc@8J$2x;CUVZ zkO@kZ4vBagK4YvbI8D