use of net.minecraftforge.common.ChestGenHooks in project BetterStorage by copygirl.
the class BackpackHandler method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
EntityLivingBase entity = event.entityLiving;
EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
ItemStack backpack = ItemBackpack.getBackpack(entity);
PropertiesBackpack backpackData;
if (backpack == null) {
backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class);
if (backpackData == null)
return;
// with a backpack, equip it with one.
if (backpackData.spawnsWithBackpack) {
ItemStack[] contents = null;
if (entity instanceof EntityFrienderman) {
backpack = new ItemStack(BetterStorageItems.itemEnderBackpack);
// Remove drop chance for the backpack.
((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
} else {
backpack = new ItemStack(BetterStorageItems.itemBackpack, 1, RandomUtils.getInt(120, 240));
ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
if (RandomUtils.getBoolean(0.15)) {
// Give the backpack a random color.
int r = RandomUtils.getInt(32, 224);
int g = RandomUtils.getInt(32, 224);
int b = RandomUtils.getInt(32, 224);
int color = (r << 16) | (g << 8) | b;
StackUtils.set(backpack, color, "display", "color");
}
contents = new ItemStack[backpackType.getBackpackColumns() * backpackType.getBackpackRows()];
// Set drop chance for the backpack to 100%.
((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 1.0F);
}
// If the entity spawned with enchanted armor,
// move the enchantments over to the backpack.
ItemStack armor = entity.getEquipmentInSlot(EquipmentSlot.CHEST);
if (armor != null && armor.isItemEnchanted()) {
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("ench", armor.getTagCompound().getTag("ench"));
backpack.setTagCompound(compound);
}
if (contents != null) {
// Add random items to the backpack.
InventoryStacks inventory = new InventoryStacks(contents);
// Add normal random backpack loot.
WeightedRandomChestContent.generateChestContents(RandomUtils.random, randomBackpackItems, inventory, 20);
// With a chance of 10%, add some random dungeon loot.
if (RandomUtils.getDouble() < 0.1) {
ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
WeightedRandomChestContent.generateChestContents(RandomUtils.random, info.getItems(RandomUtils.random), inventory, 5);
}
}
ItemBackpack.setBackpack(entity, backpack, contents);
backpackData.spawnsWithBackpack = false;
} else {
// but still has some backpack data, drop the items.
if (backpackData.contents != null) {
for (ItemStack stack : backpackData.contents) WorldUtils.dropStackFromEntity(entity, stack, 1.5F);
backpackData.contents = null;
}
}
}
ItemBackpack.getBackpackData(entity).update(entity);
if (backpack != null)
((ItemBackpack) backpack.getItem()).onEquippedUpdate(entity, backpack);
}
use of net.minecraftforge.common.ChestGenHooks in project Galacticraft by micdoodle8.
the class EntityBossBase method onDeathUpdate.
@Override
protected void onDeathUpdate() {
++this.deathTicks;
if (this.deathTicks >= 180 && this.deathTicks <= 200) {
final float x = (this.rand.nextFloat() - 0.5F) * this.width;
final float y = (this.rand.nextFloat() - 0.5F) * (this.height / 2.0F);
final float z = (this.rand.nextFloat() - 0.5F) * this.width;
this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + x, this.posY + 2.0D + y, this.posZ + z, 0.0D, 0.0D, 0.0D);
}
int i;
int j;
if (!this.worldObj.isRemote) {
if (this.deathTicks >= 180 && this.deathTicks % 5 == 0) {
GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(PacketSimple.EnumSimplePacket.C_PLAY_SOUND_EXPLODE, GCCoreUtil.getDimensionID(this.worldObj), new Object[] {}), new NetworkRegistry.TargetPoint(GCCoreUtil.getDimensionID(this.worldObj), this.posX, this.posY, this.posZ, 40.0D));
}
if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {
i = 30;
while (i > 0) {
j = EntityXPOrb.getXPSplit(i);
i -= j;
this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
}
}
}
if (this.deathTicks == 200 && !this.worldObj.isRemote) {
i = 20;
while (i > 0) {
j = EntityXPOrb.getXPSplit(i);
i -= j;
this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
}
TileEntityTreasureChest chest = null;
if (this.spawner != null && this.spawner.getChestPos() != null) {
TileEntity chestTest = this.worldObj.getTileEntity(this.spawner.getChestPos());
if (chestTest != null && chestTest instanceof TileEntityTreasureChest) {
chest = (TileEntityTreasureChest) chestTest;
}
}
if (chest == null) {
// Fallback to finding closest chest
chest = TileEntityTreasureChest.findClosest(this, this.getChestTier());
}
if (chest != null) {
double dist = this.getDistanceSq(chest.getPos().getX() + 0.5, chest.getPos().getY() + 0.5, chest.getPos().getZ() + 0.5);
if (dist < 1000 * 1000) {
if (!chest.locked) {
chest.locked = true;
}
for (int k = 0; k < chest.getSizeInventory(); k++) {
chest.setInventorySlotContents(k, null);
}
String chesttype = RoomChest.MOONCHEST;
if (this.worldObj.provider instanceof IGalacticraftWorldProvider) {
chesttype = ((IGalacticraftWorldProvider) this.worldObj.provider).getDungeonChestType();
}
ChestGenHooks info = ChestGenHooks.getInfo(chesttype);
// Generate twice, since it's an extra special chest
WeightedRandomChestContent.generateChestContents(this.rand, info.getItems(this.rand), chest, info.getCount(this.rand));
WeightedRandomChestContent.generateChestContents(this.rand, info.getItems(this.rand), chest, info.getCount(this.rand));
ItemStack schematic = this.getGuaranteedLoot(this.rand);
int slot = this.rand.nextInt(chest.getSizeInventory());
chest.setInventorySlotContents(slot, schematic);
}
}
this.dropKey();
super.setDead();
if (this.spawner != null) {
// Note: spawner.isBossDefeated is true, so it's properly dead
this.spawner.isBossDefeated = true;
this.spawner.boss = null;
this.spawner.spawned = false;
if (!this.worldObj.isRemote) {
this.spawner.lastKillTime = MinecraftServer.getCurrentTimeMillis();
}
}
}
}
use of net.minecraftforge.common.ChestGenHooks in project Galacticraft by micdoodle8.
the class WorldGenCrashedProbe method generate.
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {
for (position = position.add(-8, 0, -8); position.getY() > 5 && worldIn.isAirBlock(position); position = position.down()) {
;
}
if (position.getY() <= 4) {
return false;
}
int radius = 5 + rand.nextInt(4);
int radiusSq = radius * radius;
// Check this crater doesn't cut into a mountain
for (int poolX = -radius; poolX <= radius; poolX++) {
for (int poolY = -radius; poolY <= Math.min(256 - position.getY(), 50); poolY++) {
for (int poolZ = -radius; poolZ <= radius; poolZ++) {
BlockPos pos = new BlockPos(poolX + position.getX(), poolY + position.getY(), poolZ + position.getZ());
if (poolY > 15 && !worldIn.getBlockState(pos).getBlock().isAir(worldIn, pos)) {
return false;
}
}
}
}
for (int poolX = -radius - 1; poolX <= radius + 1; poolX++) {
for (int poolY = -radius - 1; poolY <= 256 - position.getY(); poolY++) {
for (int poolZ = -radius - 1; poolZ <= radius + 1; poolZ++) {
int distance = poolX * poolX + Math.min(0, poolY) * Math.min(0, poolY) + poolZ * poolZ;
BlockPos pos = new BlockPos(poolX + position.getX(), poolY + position.getY(), poolZ + position.getZ());
if (distance <= radiusSq) {
worldIn.setBlockState(pos, Blocks.air.getDefaultState(), 2);
} else if (worldIn.getBlockState(pos).getBlock() == VenusBlocks.venusBlock && poolY < 0 && rand.nextInt(5) == 0) {
worldIn.setBlockState(pos, VenusBlocks.scorchedRock.getDefaultState(), 2);
}
}
}
}
BlockPos blockpos = position.add(0, -radius + 1, 0);
worldIn.setBlockState(blockpos, VenusBlocks.crashedProbe.getDefaultState(), 3);
TileEntityCrashedProbe probe = (TileEntityCrashedProbe) worldIn.getTileEntity(blockpos);
if (probe != null) {
for (int i = 0; i < probe.getSizeInventory(); ++i) {
// Clear contents
probe.setInventorySlotContents(i, null);
}
ChestGenHooks info = ChestGenHooks.getInfo(BlockCrashedProbe.CRASHED_PROBE);
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), probe, info.getCount(rand));
probe.setDropCore();
}
return true;
}
use of net.minecraftforge.common.ChestGenHooks in project Galacticraft by micdoodle8.
the class RoomChestVenus method addComponentParts.
@Override
public boolean addComponentParts(World worldIn, Random rand, StructureBoundingBox boundingBox) {
if (super.addComponentParts(worldIn, rand, boundingBox)) {
int chestX = this.sizeX / 2;
int chestY = 1;
int chestZ = this.sizeZ / 2;
this.setBlockState(worldIn, Blocks.chest.getDefaultState().withProperty(BlockTier1TreasureChest.FACING, this.getDirection().getOpposite()), chestX, chestY, chestZ, boundingBox);
BlockPos blockpos = new BlockPos(this.getXWithOffset(chestX, chestZ), this.getYWithOffset(chestY), this.getZWithOffset(chestX, chestZ));
TileEntityChest chest = (TileEntityChest) worldIn.getTileEntity(blockpos);
if (chest != null) {
for (int i = 0; i < chest.getSizeInventory(); ++i) {
// Clear contents
chest.setInventorySlotContents(i, null);
}
ChestGenHooks info = ChestGenHooks.getInfo(VENUSCHEST);
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), chest, info.getCount(rand));
}
return true;
}
return false;
}
use of net.minecraftforge.common.ChestGenHooks in project Galacticraft by micdoodle8.
the class RoomChest method addComponentParts.
@Override
public boolean addComponentParts(World worldIn, Random rand, StructureBoundingBox boundingBox) {
if (super.addComponentParts(worldIn, rand, boundingBox)) {
int chestX = this.sizeX / 2;
int chestY = 1;
int chestZ = this.sizeZ / 2;
this.setBlockState(worldIn, Blocks.chest.getDefaultState().withProperty(BlockTier1TreasureChest.FACING, this.getDirection().getOpposite()), chestX, chestY, chestZ, boundingBox);
BlockPos blockpos = new BlockPos(this.getXWithOffset(chestX, chestZ), this.getYWithOffset(chestY), this.getZWithOffset(chestX, chestZ));
TileEntityChest chest = (TileEntityChest) worldIn.getTileEntity(blockpos);
if (chest != null) {
for (int i = 0; i < chest.getSizeInventory(); ++i) {
// Clear contents
chest.setInventorySlotContents(i, null);
}
String chesttype = MOONCHEST;
if (worldIn.provider instanceof IGalacticraftWorldProvider) {
chesttype = ((IGalacticraftWorldProvider) worldIn.provider).getDungeonChestType();
}
ChestGenHooks info = ChestGenHooks.getInfo(chesttype);
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), chest, info.getCount(rand));
}
return true;
}
return false;
}
Aggregations