Search in sources :

Example 1 with EntityBlackHoleStorage

use of stevekung.mods.moreplanets.entity.EntityBlackHoleStorage in project MorePlanets by SteveKunG.

the class BlockBlackHoleStorage method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack itemStack) {
    TileEntity tile = world.getTileEntity(pos);
    world.setBlockState(pos, this.getDefaultState());
    if (!world.isRemote) {
        if (placer instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) placer;
            EntityBlackHoleStorage blackHole = new EntityBlackHoleStorage(world);
            blackHole.setTileEntityPos(pos);
            blackHole.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 2, pos.getZ() + 0.5D, 0.0F, 0.0F);
            world.spawnEntity(blackHole);
            world.playSound(null, pos.getX() + 0.5D, pos.getY() + 2, pos.getZ() + 0.5D, MPSounds.BLACK_HOLE_CREATED, SoundCategory.BLOCKS, 1.0F, 1.0F);
            if (tile instanceof TileEntityBlackHoleStorage) {
                TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
                storage.ownerUUID = player.getGameProfile().getId().toString();
                if (itemStack.hasTagCompound()) {
                    storage.inventory = NonNullList.withSize(storage.getSizeInventory(), ItemStack.EMPTY);
                    storage.disableBlackHole = itemStack.getTagCompound().getBoolean("Disable");
                    storage.useHopper = itemStack.getTagCompound().getBoolean("Hopper");
                    storage.collectMode = itemStack.getTagCompound().getString("Mode");
                    ItemStackHelper.loadAllItems(itemStack.getTagCompound(), storage.inventory);
                    // TODO: Remove in 1.13
                    if (itemStack.getTagCompound().hasKey("XP")) {
                        NBTTagCompound fluidNbt = new NBTTagCompound();
                        fluidNbt.setString("FluidName", "xpjuice");
                        fluidNbt.setInteger("Amount", itemStack.getTagCompound().getInteger("XP"));
                        storage.fluidTank.readFromNBT(fluidNbt);
                    } else {
                        storage.fluidTank.readFromNBT(itemStack.getTagCompound().getCompoundTag("XpFluid"));
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBlackHoleStorage(stevekung.mods.moreplanets.tileentity.TileEntityBlackHoleStorage) EntityBlackHoleStorage(stevekung.mods.moreplanets.entity.EntityBlackHoleStorage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntityBlackHoleStorage(stevekung.mods.moreplanets.tileentity.TileEntityBlackHoleStorage)

Example 2 with EntityBlackHoleStorage

use of stevekung.mods.moreplanets.entity.EntityBlackHoleStorage in project MorePlanets by SteveKunG.

the class TileEntityBlackHoleStorage method update.

@Override
public void update() {
    super.update();
    this.renderTicks++;
    if (this.initialize) {
        this.renderTicks = this.renderTicks + this.world.rand.nextInt(100);
        this.initialize = false;
    }
    if (this.ticks % 20 == 0) {
        this.world.playSound(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), MPSounds.BLACK_HOLE_AMBIENT, SoundCategory.BLOCKS, 1.0F, 1.0F);
    }
    if (this.world != null && !this.world.isRemote) {
        this.updateStorage();
        List<EntityBlackHoleStorage> blackHoleList = this.world.getEntitiesWithinAABB(EntityBlackHoleStorage.class, new AxisAlignedBB(this.pos.getX(), this.pos.getY() + 2, this.pos.getZ(), this.pos.getX() + 1.0D, this.pos.getY() + 3, this.pos.getZ() + 1.0D));
        for (EntityBlackHoleStorage bh : blackHoleList) {
            bh.setDisable(this.disableBlackHole);
            bh.setCollectMode(this.collectMode);
        }
        if (blackHoleList.isEmpty()) {
            JsonUtil json = new JsonUtil();
            EntityPlayer player = this.world.getPlayerEntityByUUID(UUID.fromString(this.ownerUUID));
            this.destroyBlock();
            if (player != null) {
                player.sendMessage(json.text(GCCoreUtil.translate("gui.black_hole_disappear.message")).setStyle(json.red()));
            }
        }
        this.xpTemp = this.fluidTank.getFluidAmount();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityBlackHoleStorage(stevekung.mods.moreplanets.entity.EntityBlackHoleStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityBlackHoleStorage (stevekung.mods.moreplanets.entity.EntityBlackHoleStorage)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 TileEntityBlackHoleStorage (stevekung.mods.moreplanets.tileentity.TileEntityBlackHoleStorage)1 JsonUtil (stevekung.mods.moreplanets.util.JsonUtil)1