mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 19:05:16 +00:00
The Loonium now spawns mobs that drop dungeon loot instead of spawning dungeon loot outright.
This commit is contained in:
1 parent
5f56dfb511
commit
39bf519f57
3 files changed
+116
-14
No files matched your search
@@ -13,12 +13,35 @@ package vazkii.botania.common.block.subtile.functional;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.monster.EntityCaveSpider;
|
||||
import net.minecraft.entity.monster.EntityCreeper;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.monster.EntitySpider;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.monster.SkeletonType;
|
||||
import net.minecraft.entity.monster.ZombieType;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.subtile.RadiusDescriptor;
|
||||
@@ -28,33 +51,96 @@ import vazkii.botania.common.lexicon.LexiconData;
|
||||
public class SubTileLoonuim extends SubTileFunctional {
|
||||
|
||||
private static final int COST = 35000;
|
||||
private static final int RANGE = 3;
|
||||
private static final int RANGE = 5;
|
||||
private static final String TAG_LOOT_TABLE = "lootTable";
|
||||
private static final String TAG_ITEMSTACK_TO_DROP = "botania:looniumItemStackToDrop";
|
||||
|
||||
private ResourceLocation lootTable = new ResourceLocation("minecraft", "chests/simple_dungeon");
|
||||
|
||||
private static boolean registered = false;
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
if(!supertile.getWorld().isRemote && redstoneSignal == 0 && ticksExisted % 200 == 0 && mana >= COST) {
|
||||
Random rand = supertile.getWorld().rand;
|
||||
|
||||
if(!registered) {
|
||||
MinecraftForge.EVENT_BUS.register(DropHandler.class);
|
||||
registered = true;
|
||||
}
|
||||
|
||||
World world = supertile.getWorld();
|
||||
if(!world.isRemote && redstoneSignal == 0 && ticksExisted % 100 == 0 && mana >= COST) {
|
||||
Random rand = world.rand;
|
||||
|
||||
ItemStack stack;
|
||||
do {
|
||||
List<ItemStack> stacks = supertile.getWorld().getLootTableManager().getLootTableFromLocation(lootTable).generateLootForPools(rand, new LootContext.Builder((WorldServer) supertile.getWorld()).build());
|
||||
List<ItemStack> stacks = world.getLootTableManager().getLootTableFromLocation(lootTable).generateLootForPools(rand, new LootContext.Builder((WorldServer) world).build());
|
||||
if (stacks.isEmpty())
|
||||
return;
|
||||
else stack = stacks.get(0);
|
||||
} while(stack == null || BotaniaAPI.looniumBlacklist.contains(stack.getItem()));
|
||||
|
||||
int bound = RANGE * 2 + 1;
|
||||
EntityItem entity = new EntityItem(supertile.getWorld(), supertile.getPos().getX() - RANGE + rand.nextInt(bound) , supertile.getPos().getY() + 1, supertile.getPos().getZ() - RANGE + rand.nextInt(bound), stack);
|
||||
entity.motionX = 0;
|
||||
entity.motionY = 0;
|
||||
entity.motionZ = 0;
|
||||
int xp = supertile.getPos().getX() - RANGE + rand.nextInt(bound);
|
||||
int yp = supertile.getPos().getY();
|
||||
int zp = supertile.getPos().getZ() - RANGE + rand.nextInt(bound);
|
||||
|
||||
BlockPos pos = new BlockPos(xp, yp - 1, zp);
|
||||
do {
|
||||
pos = pos.up();
|
||||
if(pos.getY() >= 254)
|
||||
return;
|
||||
} while(world.getBlockState(pos).getBlock().isVisuallyOpaque());
|
||||
pos = pos.up();
|
||||
|
||||
supertile.getWorld().spawnEntityInWorld(entity);
|
||||
double x = pos.getX() + Math.random();
|
||||
double y = pos.getY() + Math.random();
|
||||
double z = pos.getZ() + Math.random();
|
||||
|
||||
EntityMob entity = null;
|
||||
if(world.rand.nextInt(50) == 0)
|
||||
entity = new EntityEnderman(world);
|
||||
else if(world.rand.nextInt(10) == 0) {
|
||||
entity = new EntityCreeper(world);
|
||||
if(world.rand.nextInt(200) == 0)
|
||||
((EntityCreeper) entity).onStruckByLightning(null);
|
||||
} else
|
||||
switch(world.rand.nextInt(3)) {
|
||||
case 0:
|
||||
entity = new EntityZombie(world);
|
||||
if(world.rand.nextInt(10) == 0)
|
||||
((EntityZombie) entity).func_189778_a(ZombieType.HUSK); // set zombie type
|
||||
break;
|
||||
case 1:
|
||||
entity = new EntitySkeleton(world);
|
||||
if(world.rand.nextInt(10) == 0)
|
||||
((EntitySkeleton) entity).func_189768_a(SkeletonType.STRAY); // set skeleton type
|
||||
break;
|
||||
case 2:
|
||||
if(world.rand.nextInt(10) == 0)
|
||||
entity = new EntityCaveSpider(world);
|
||||
else entity = new EntitySpider(world);
|
||||
break;
|
||||
}
|
||||
|
||||
entity.setPositionAndRotation(x, y, z, world.rand.nextFloat() * 360F, 0);
|
||||
entity.motionX = entity.motionY = entity.motionZ = 0;
|
||||
|
||||
Multimap map = HashMultimap.create();
|
||||
map.put(SharedMonsterAttributes.MAX_HEALTH.getAttributeUnlocalizedName(), new AttributeModifier("Loonium Modififer Health", 2, 1));
|
||||
map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier("Loonium Modififer Damage", 1.5, 1));
|
||||
entity.getAttributeMap().applyAttributeModifiers(map);
|
||||
|
||||
entity.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, Integer.MAX_VALUE, 0));
|
||||
entity.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, Integer.MAX_VALUE, 0));
|
||||
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
stack.writeToNBT(cmp);
|
||||
entity.getEntityData().setTag(TAG_ITEMSTACK_TO_DROP, cmp);
|
||||
|
||||
world.spawnEntityInWorld(entity);
|
||||
entity.onInitialSpawn(world.getDifficultyForLocation(pos), null);
|
||||
SubTileSpectranthemum.spawnExplosionParticles(entity, 5);
|
||||
|
||||
mana -= COST;
|
||||
sync();
|
||||
}
|
||||
@@ -97,5 +183,21 @@ public class SubTileLoonuim extends SubTileFunctional {
|
||||
super.writeToPacketNBT(cmp);
|
||||
cmp.setString(TAG_LOOT_TABLE, lootTable.toString());
|
||||
}
|
||||
|
||||
public static class DropHandler {
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public static void onDrops(LivingDropsEvent event) {
|
||||
System.out.println("call");
|
||||
EntityLivingBase e = event.getEntityLiving();
|
||||
if(e.getEntityData().hasKey(TAG_ITEMSTACK_TO_DROP)) {
|
||||
NBTTagCompound cmp = e.getEntityData().getCompoundTag(TAG_ITEMSTACK_TO_DROP);
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(cmp);
|
||||
event.getDrops().clear();
|
||||
event.getDrops().add(new EntityItem(e.worldObj, e.posX, e.posY, e.posZ, stack));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -13,6 +13,7 @@ package vazkii.botania.common.block.subtile.functional;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -93,9 +94,8 @@ public class SubTileSpectranthemum extends SubTileFunctional {
|
||||
}
|
||||
}
|
||||
|
||||
static void spawnExplosionParticles(EntityItem item, int p) {
|
||||
PacketHandler.sendToNearby(item.worldObj, new BlockPos(item),
|
||||
new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.ITEM_SMOKE, item.posX, item.posY, item.posZ, item.getEntityId(), p));
|
||||
static void spawnExplosionParticles(Entity item, int p) {
|
||||
PacketHandler.sendToNearby(item.worldObj, new BlockPos(item), new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.ITEM_SMOKE, item.posX, item.posY, item.posZ, item.getEntityId(), p));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2397,7 +2397,7 @@ botania.page.clayconia1=&oWhat a killer joke&r.
|
||||
# -- LOONIUM
|
||||
botania.entry.loonium=Loonium
|
||||
botania.tagline.loonium=Conjures dungeon loot
|
||||
botania.page.loonium0=Any weary adventurer knows that &4Dungeons&0 can hold valuable goodies. The &1Loonium&0 can, at the use of an extreme amount of &4Mana&0, materialize these items and drop them in the nearby vicinity.
|
||||
botania.page.loonium0=Any weary adventurer knows that &4Dungeons&0 can hold valuable goodies. The &1Loonium&0 can, at the use of an extreme amount of &4Mana&0, materialize these items for said aventurers to collect.<br>There's a catch, though. Alongside the item, a monster is spawned to protect it. These monsters are stronger than usual, and will drop a random piece of &4dungeon loot&0 when killed.
|
||||
botania.page.loonium1=&oThe mighty flower for epic loot&r!
|
||||
|
||||
# -- DAFFOMILL
|
||||
|
||||
Reference in new issue
Block a user