Search in sources :

Example 1 with ITileEntityProvider

use of net.minecraft.block.ITileEntityProvider in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityFallingUpBlock method onUpdate.

@Override
public void onUpdate() {
    Block block = this.fallTile.getBlock();
    if (this.fallTile.getMaterial() == Material.AIR) {
        this.setDead();
    } else {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        if (this.fallTime++ == 0) {
            BlockPos blockpos = new BlockPos(this);
            if (this.worldObj.getBlockState(blockpos).getBlock() == block) {
                this.worldObj.setBlockToAir(blockpos);
            } else if (!this.worldObj.isRemote) {
                this.setDead();
                return;
            }
        }
        if (!this.hasNoGravity()) {
            this.motionY += 0.03999999910593033D;
        }
        CallRunner.onEntityMove(this, this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.9800000190734863D;
        this.motionY *= 0.9800000190734863D;
        this.motionZ *= 0.9800000190734863D;
        if (!this.worldObj.isRemote) {
            BlockPos blockpos1 = new BlockPos(this);
            if (!onGround && isCollidedVertically) {
                IBlockState iblockstate = this.worldObj.getBlockState(blockpos1);
                if (// Forge: Don't indent below.
                this.worldObj.isAirBlock(new BlockPos(this.posX, this.posY + 1.009999999776482582D, this.posZ)))
                    if (BlockFalling.canFallThrough(this.worldObj.getBlockState(new BlockPos(this.posX, this.posY + 1.009999999776482582D, this.posZ)))) {
                        this.isCollidedVertically = false;
                        return;
                    }
                this.motionX *= 0.699999988079071D;
                this.motionZ *= 0.699999988079071D;
                this.motionY *= -0.5D;
                if (iblockstate.getBlock() != Blocks.PISTON_EXTENSION) {
                    this.setDead();
                    if (!this.canSetAsBlock) {
                        if (this.worldObj.canBlockBePlaced(block, blockpos1, true, EnumFacing.UP, (Entity) null, (ItemStack) null) && !BlockFalling.canFallThrough(this.worldObj.getBlockState(blockpos1.up())) && worldObj.setBlockState(blockpos1, this.fallTile, 3)) {
                            if (block instanceof BlockFalling) {
                                ((BlockFalling) block).onEndFalling(this.worldObj, blockpos1);
                            }
                            if (this.tileEntityData != null && block instanceof ITileEntityProvider) {
                                TileEntity tileentity = this.worldObj.getTileEntity(blockpos1);
                                if (tileentity != null) {
                                    NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                                    for (String s : this.tileEntityData.getKeySet()) {
                                        NBTBase nbtbase = this.tileEntityData.getTag(s);
                                        if (!"x".equals(s) && !"y".equals(s) && !"z".equals(s)) {
                                            nbttagcompound.setTag(s, nbtbase.copy());
                                        }
                                    }
                                    tileentity.readFromNBT(nbttagcompound);
                                    tileentity.markDirty();
                                }
                            }
                        } else if (this.shouldDropItem && this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
                            this.entityDropItem(new ItemStack(block, 1, block.damageDropped(this.fallTile)), 0.0F);
                        }
                    }
                }
            } else if (this.fallTime > 100 && !this.worldObj.isRemote && (blockpos1.getY() < 1 || blockpos1.getY() > 256) || this.fallTime > 600) {
                if (this.shouldDropItem && this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
                    this.entityDropItem(new ItemStack(block, 1, block.damageDropped(this.fallTile)), 0.0F);
                }
                this.setDead();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) IBlockState(net.minecraft.block.state.IBlockState) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockFalling(net.minecraft.block.BlockFalling) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ITileEntityProvider

use of net.minecraft.block.ITileEntityProvider in project SecurityCraft by Geforce132.

the class GuiSCManual method updateRecipeAndIcons.

private void updateRecipeAndIcons() {
    if (currentPage < 0) {
        recipe = null;
        hoverCheckers.clear();
        return;
    }
    hoverCheckers.clear();
    if (SecurityCraft.instance.manualPages.get(currentPage).hasCustomRecipe())
        recipe = SecurityCraft.instance.manualPages.get(currentPage).getRecipe();
    else
        for (Object object : CraftingManager.getInstance().getRecipeList()) {
            if (object instanceof ShapedRecipes) {
                ShapedRecipes recipe = (ShapedRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = recipe.recipeItems;
                    break;
                }
            } else if (object instanceof ShapelessRecipes) {
                ShapelessRecipes recipe = (ShapelessRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = toItemStackArray(recipe.recipeItems);
                    break;
                }
            }
            recipe = null;
        }
    if (recipe != null) {
        outer: for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if ((i * 3) + j == recipe.length)
                    break outer;
                if (recipe[(i * 3) + j] != null)
                    hoverCheckers.add(new CustomHoverChecker(144 + (i * 20), 144 + (i * 20) + 16, (k + 100) + (j * 20), (k + 100) + (j * 20) + 16, 20, recipe[(i * 3) + j].getDisplayName()));
            }
        }
    } else if (SecurityCraft.instance.manualPages.get(currentPage).isRecipeDisabled())
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.disabled")));
    else if (SecurityCraft.instance.manualPages.get(currentPage).getHelpInfo().equals("help.reinforced.info"))
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe.reinforced")));
    else {
        String name = SecurityCraft.instance.manualPages.get(currentPage).getItem().getUnlocalizedName().substring(5);
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe." + name)));
    }
    Item item = SecurityCraft.instance.manualPages.get(currentPage).getItem();
    TileEntity te = ((item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof ITileEntityProvider) ? ((ITileEntityProvider) ((ItemBlock) item).getBlock()).createNewTileEntity(Minecraft.getMinecraft().theWorld, 0) : null);
    Block itemBlock = ((item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : null);
    if (te != null) {
        if (te instanceof IOwnable)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 29, (k + 29) + 16, 20, StatCollector.translateToLocal("gui.scManual.ownableBlock")));
        if (te instanceof IPasswordProtected)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 55, (k + 55) + 16, 20, StatCollector.translateToLocal("gui.scManual.passwordProtectedBlock")));
        if (te instanceof TileEntitySCTE && ((TileEntitySCTE) te).isActivatedByView())
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 81, (k + 81) + 16, 20, StatCollector.translateToLocal("gui.scManual.viewActivatedBlock")));
        if (itemBlock instanceof IExplosive)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 107, (k + 107) + 16, 20, StatCollector.translateToLocal("gui.scManual.explosiveBlock")));
        if (te instanceof CustomizableSCTE)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 213, (k + 213) + 16, 20, StatCollector.translateToLocal("gui.scManual.customizableBlock")));
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomHoverChecker(net.geforcemods.securitycraft.gui.components.CustomHoverChecker) TileEntitySCTE(net.geforcemods.securitycraft.api.TileEntitySCTE) ItemBlock(net.minecraft.item.ItemBlock) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) IExplosive(net.geforcemods.securitycraft.api.IExplosive) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 3 with ITileEntityProvider

use of net.minecraft.block.ITileEntityProvider in project SpongeCommon by SpongePowered.

the class MixinWorldServer method createSpongeBlockSnapshot.

@Override
public SpongeBlockSnapshot createSpongeBlockSnapshot(IBlockState state, IBlockState extended, BlockPos pos, BlockChangeFlag updateFlag) {
    this.builder.reset();
    this.builder.blockState((BlockState) state).extendedState((BlockState) extended).worldId(this.getUniqueId()).position(VecHelper.toVector3i(pos));
    Optional<UUID> creator = getCreator(pos.getX(), pos.getY(), pos.getZ());
    Optional<UUID> notifier = getNotifier(pos.getX(), pos.getY(), pos.getZ());
    if (creator.isPresent()) {
        this.builder.creator(creator.get());
    }
    if (notifier.isPresent()) {
        this.builder.notifier(notifier.get());
    }
    if (state.getBlock() instanceof ITileEntityProvider) {
        // We MUST only check to see if a TE exists to avoid creating a new one.
        final net.minecraft.tileentity.TileEntity te = this.getChunkFromBlockCoords(pos).getTileEntity(pos, net.minecraft.world.chunk.Chunk.EnumCreateEntityType.CHECK);
        if (te != null) {
            TileEntity tile = (TileEntity) te;
            for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) tile).getCustomManipulators()) {
                this.builder.add(manipulator);
            }
            NBTTagCompound nbt = new NBTTagCompound();
            // Some mods like OpenComputers assert if attempting to save robot while moving
            try {
                te.writeToNBT(nbt);
                this.builder.unsafeNbt(nbt);
            } catch (Throwable t) {
            // ignore
            }
        }
    }
    return new SpongeBlockSnapshot(this.builder, (SpongeBlockChangeFlag) updateFlag);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) UUID(java.util.UUID)

Example 4 with ITileEntityProvider

use of net.minecraft.block.ITileEntityProvider in project SecurityCraft by Geforce132.

the class GuiSCManual method drawScreen.

@Override
public void drawScreen(int par1, int par2, float par3) {
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    if (update) {
        updateRecipeAndIcons();
        update = false;
    }
    if (currentPage == -1)
        mc.getTextureManager().bindTexture(infoBookTitlePage);
    else if (recipe != null || SecurityCraft.instance.manualPages.get(currentPage).isRecipeDisabled())
        mc.getTextureManager().bindTexture(infoBookTexture);
    else
        mc.getTextureManager().bindTexture(infoBookTextureSpecial);
    this.drawTexturedModalRect(k, 5, 0, 0, 256, 250);
    if (currentPage > -1) {
        if (SecurityCraft.instance.manualPages.get(currentPage).getHelpInfo().equals("help.reinforced.info"))
            fontRendererObj.drawString(StatCollector.translateToLocal("gui.scManual.reinforced"), k + 39, 27, 0, false);
        else
            fontRendererObj.drawString(StatCollector.translateToLocal(SecurityCraft.instance.manualPages.get(currentPage).getItem().getUnlocalizedName() + ".name"), k + 39, 27, 0, false);
        fontRendererObj.drawSplitString(StatCollector.translateToLocal(SecurityCraft.instance.manualPages.get(currentPage).getHelpInfo()), k + 18, 45, 225, 0);
    } else {
        fontRendererObj.drawString(StatCollector.translateToLocal("gui.scManual.intro.1"), k + 39, 27, 0, false);
        fontRendererObj.drawString(StatCollector.translateToLocal("gui.scManual.intro.2"), k + 60, 159, 0, false);
        if (StatCollector.canTranslate("gui.scManual.author"))
            fontRendererObj.drawString(StatCollector.translateToLocal("gui.scManual.author"), k + 65, 170, 0, false);
    }
    for (int i = 0; i < buttonList.size(); i++) ((GuiButton) buttonList.get(i)).drawButton(mc, par1, par2);
    if (currentPage > -1) {
        Item item = SecurityCraft.instance.manualPages.get(currentPage).getItem();
        GuiUtils.drawItemStackToGui(mc, item, k + 19, 22, !(SecurityCraft.instance.manualPages.get(currentPage).getItem() instanceof ItemBlock));
        mc.getTextureManager().bindTexture(infoBookIcons);
        TileEntity te = ((item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof ITileEntityProvider) ? ((ITileEntityProvider) ((ItemBlock) item).getBlock()).createNewTileEntity(Minecraft.getMinecraft().theWorld, 0) : null);
        Block itemBlock = ((item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : null);
        if (itemBlock != null) {
            if (itemBlock instanceof IExplosive)
                this.drawTexturedModalRect(k + 107, 117, 54, 1, 18, 18);
            if (te != null) {
                if (te instanceof IOwnable)
                    this.drawTexturedModalRect(k + 29, 118, 1, 1, 16, 16);
                if (te instanceof IPasswordProtected)
                    this.drawTexturedModalRect(k + 55, 118, 18, 1, 17, 16);
                if (te instanceof TileEntitySCTE && ((TileEntitySCTE) te).isActivatedByView())
                    this.drawTexturedModalRect(k + 81, 118, 36, 1, 17, 16);
                if (te instanceof CustomizableSCTE)
                    this.drawTexturedModalRect(k + 213, 118, 72, 1, 16, 16);
            }
        }
        if (recipe != null) {
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (((i * 3) + j) >= recipe.length)
                        break;
                    if (recipe[(i * 3) + j] == null)
                        continue;
                    if (recipe[(i * 3) + j].getItem() instanceof ItemBlock)
                        GuiUtils.drawItemStackToGui(mc, Block.getBlockFromItem(recipe[(i * 3) + j].getItem()), (k + 100) + (j * 20), 144 + (i * 20), !(recipe[(i * 3) + j].getItem() instanceof ItemBlock));
                    else
                        GuiUtils.drawItemStackToGui(mc, recipe[(i * 3) + j].getItem(), recipe[(i * 3) + j].getItemDamage(), (k + 100) + (j * 20), 144 + (i * 20), !(recipe[(i * 3) + j].getItem() instanceof ItemBlock));
                }
            }
        }
        for (CustomHoverChecker chc : hoverCheckers) {
            if (chc != null && chc.checkHover(par1, par2)) {
                if (chc.getName() != null)
                    drawHoveringText(mc.fontRendererObj.listFormattedStringToWidth(chc.getName(), 250), par1, par2, mc.fontRendererObj);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) CustomHoverChecker(net.geforcemods.securitycraft.gui.components.CustomHoverChecker) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) TileEntitySCTE(net.geforcemods.securitycraft.api.TileEntitySCTE) IExplosive(net.geforcemods.securitycraft.api.IExplosive) ItemBlock(net.minecraft.item.ItemBlock)

Example 5 with ITileEntityProvider

use of net.minecraft.block.ITileEntityProvider in project SpongeCommon by SpongePowered.

the class SpongeBlockSnapshot method createArchetype.

@Override
public Optional<TileEntityArchetype> createArchetype() {
    final BlockType type = this.blockState.getType();
    if (!(type instanceof ITileEntityProvider)) {
        return Optional.empty();
    }
    if (this.compound == null) {
        // We can't retrieve the TileEntityType
        return Optional.empty();
    }
    final String tileId = this.compound.getString(NbtDataUtil.BLOCK_ENTITY_ID);
    final Class<? extends TileEntity> tileClass = TileEntity.REGISTRY.getObject(new ResourceLocation(tileId));
    if (tileClass == null) {
        return Optional.empty();
    }
    final TileEntityType tileType = TileEntityTypeRegistryModule.getInstance().getForClass(tileClass);
    final TileEntityArchetype archetype = TileEntityArchetype.builder().tile(tileType).state(this.blockState).tileData(NbtTranslator.getInstance().translate(this.compound)).build();
    return Optional.of(archetype);
}
Also used : ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockType(org.spongepowered.api.block.BlockType) TileEntityType(org.spongepowered.api.block.tileentity.TileEntityType) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityArchetype(org.spongepowered.api.block.tileentity.TileEntityArchetype)

Aggregations

ITileEntityProvider (net.minecraft.block.ITileEntityProvider)8 TileEntity (net.minecraft.tileentity.TileEntity)6 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)2 IExplosive (net.geforcemods.securitycraft.api.IExplosive)2 IOwnable (net.geforcemods.securitycraft.api.IOwnable)2 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)2 TileEntitySCTE (net.geforcemods.securitycraft.api.TileEntitySCTE)2 CustomHoverChecker (net.geforcemods.securitycraft.gui.components.CustomHoverChecker)2 Item (net.minecraft.item.Item)2 ItemBlock (net.minecraft.item.ItemBlock)2 ItemStack (net.minecraft.item.ItemStack)2 IMixinCustomDataHolder (org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)2 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1 EntityHangingSchematic (micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic)1 IMultiBlock (micdoodle8.mods.galacticraft.core.tile.IMultiBlock)1 TileEntityCargoLoader (micdoodle8.mods.galacticraft.core.tile.TileEntityCargoLoader)1