From 3523837e3e411bed3df43e3ac8189d71b79fd59f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 12 Mar 2019 19:34:59 +0100 Subject: [PATCH] projectile generator, part 1 --- .../de/ellpeck/naturesaura/ModConfig.java | 14 +++++ .../naturesaura/api/NaturesAuraAPI.java | 5 ++ .../blocks/BlockProjectileGenerator.java | 56 +++++++++++++++++++ .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../tiles/TileEntityProjectileGenerator.java | 26 +++++++++ .../naturesaura/recipes/ModRecipes.java | 9 +++ 6 files changed, 111 insertions(+) create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityProjectileGenerator.java diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index da7b55ec..53069a8c 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -31,6 +31,9 @@ public final class ModConfig { @Comment("Additional blocks that are recognized as generatable ores for the passive ore generation effect. Each entry needs to be formatted as oredictEntry:oreWeight:dimension where a higher weight makes the ore more likely to spawn with 5000 being the weight of coal, the default ore with the highest weight, and dimension being any of overworld and nether") public String[] additionalOres = new String[0]; + @Comment("Additional projectile types that are allowed to be consumed by the projectile generator. Each entry needs to be formatted as entity_registry_name->aura_amount") + public String[] additionalProjectiles = new String[0]; + @Comment("The amount of blocks that can be between two Aura Field Creators for them to be connectable and work together") public int fieldCreatorRange = 10; @@ -124,6 +127,17 @@ public final class ModConfig { } catch (Exception e) { NaturesAura.LOGGER.warn("Error parsing additionalOres", e); } + + try { + for (String s : general.additionalProjectiles) { + String[] split = s.split("->"); + ResourceLocation name = new ResourceLocation(split[0]); + int amount = Integer.parseInt(split[1]); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(name, amount); + } + } catch (Exception e) { + NaturesAura.LOGGER.warn("Error parsing additionalProjectiles", e); + } } } } diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 4739b39c..43c9017e 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -124,6 +124,11 @@ public final class NaturesAuraAPI { * spawn inside of netherrack blocks in the nether */ public static final List NETHER_ORES = new ArrayList<>(); + /** + * A map of all of the entities' registry names to the amounts of aura they + * each generate in the projectile generator + */ + public static final Map PROJECTILE_GENERATIONS = new HashMap<>(); /** * The capability for any item or block that stores Aura in the form of an diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java new file mode 100644 index 00000000..25663ef1 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java @@ -0,0 +1,56 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.blocks.tiles.TileEntityProjectileGenerator; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.ProjectileImpactEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class BlockProjectileGenerator extends BlockContainerImpl { + public BlockProjectileGenerator() { + super(Material.ROCK, "projectile_generator", TileEntityProjectileGenerator.class, "projectile_generator"); + this.setSoundType(SoundType.STONE); + this.setHardness(2.5F); + + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onProjectileImpact(ProjectileImpactEvent event) { + Entity entity = event.getEntity(); + if (entity.world.isRemote) + return; + RayTraceResult ray = event.getRayTraceResult(); + BlockPos pos = ray.getBlockPos(); + if (pos == null) + return; + TileEntity tile = entity.world.getTileEntity(pos); + if (!(tile instanceof TileEntityProjectileGenerator)) + return; + TileEntityProjectileGenerator generator = (TileEntityProjectileGenerator) tile; + if (generator.nextSide != ray.sideHit) + return; + ResourceLocation name = EntityList.getKey(entity); + int amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(name); + if (amount <= 0) + return; + + BlockPos spot = IAuraChunk.getLowestSpot(entity.world, pos, 35, pos); + IAuraChunk.getAuraChunk(entity.world, spot).storeAura(spot, amount); + + generator.nextSide = generator.nextSide.rotateY(); + generator.sendToClients(); + + entity.setDead(); + event.setCanceled(true); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index 0a266864..d4eb5bf7 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -52,4 +52,5 @@ public final class ModBlocks { public static final Block ENDER_CRATE = new BlockEnderCrate(); public static final Block POWDER_PLACER = new BlockPowderPlacer(); public static final Block FIREWORK_GENERATOR = new BlockFireworkGenerator(); + public static final Block PROJECTILE_GENERATOR = new BlockProjectileGenerator(); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityProjectileGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityProjectileGenerator.java new file mode 100644 index 00000000..72068c54 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityProjectileGenerator.java @@ -0,0 +1,26 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; + +public class TileEntityProjectileGenerator extends TileEntityImpl { + + public EnumFacing nextSide = EnumFacing.NORTH; + + @Override + public void writeNBT(NBTTagCompound compound, SaveType type) { + super.writeNBT(compound, type); + if (type != SaveType.BLOCK) { + compound.setInteger("next_side", this.nextSide.getHorizontalIndex()); + } + } + + @Override + public void readNBT(NBTTagCompound compound, SaveType type) { + super.readNBT(compound, type); + if (type != SaveType.BLOCK) { + this.nextSide = EnumFacing.byHorizontalIndex(compound.getInteger("next_side")); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java index f399cd63..17314f33 100644 --- a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java +++ b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java @@ -340,6 +340,15 @@ public final class ModRecipes { NaturesAuraAPI.NETHER_ORES.add(new WeightedOre("oreCobalt", 50)); NaturesAuraAPI.NETHER_ORES.add(new WeightedOre("oreArdite", 50)); + + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("egg"), 2500); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("snowball"), 3500); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("small_fireball"), 15000); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("ender_pearl"), 30000); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("xp_bottle"), 75000); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("arrow"), 10000); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("shulker_bullet"), 250000); + NaturesAuraAPI.PROJECTILE_GENERATIONS.put(new ResourceLocation("llama_spit"), 80000); } private static void spawner(String name, String entity, int aura, int time, Ingredient... ings) {