net.minecraft.block.ITileEntityProvider Java Examples

The following examples show how to use net.minecraft.block.ITileEntityProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MovementDataProviderDefault.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void readMovementInfo(IMovingBlock block, NBTTagCompound tag) {

    block.setBlock(GameData.getBlockRegistry().getObject(tag.getString("block")));
    block.setMetadata(tag.getInteger("metadata"));
    TileEntity te = block.getTileEntity();

    if (tag.hasKey("data") && (te != null || block.getBlock() instanceof ITileEntityProvider)) {
        if (te == null) {
            te = ((ITileEntityProvider) block.getBlock()).createNewTileEntity(FakeWorld.getFakeWorld((MovingBlock) block),
                    block.getMetadata());
            System.out.println("creating!");
        }
        if (te != null) {
            te.readFromNBT(tag.getCompoundTag("data"));
            block.setTileEntity(te);
        }
    }

    ((MovingBlock) block).setRenderList(-1);
}
 
Example #2
Source File: BW_ItemBlocks.java    From bartworks with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) {
    if (this.field_150939_a instanceof BW_GlasBlocks)
        aList.add(StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(BW_Util.getTierFromGlasMeta(aStack.getItemDamage())) + GT_Values.VN[BW_Util.getTierFromGlasMeta(aStack.getItemDamage())]);
    if (this.field_150939_a instanceof ITileAddsInformation) {
        aList.addAll(Arrays.asList(((ITileAddsInformation) this.field_150939_a).getInfoData()));
    }
    aList.add(this.mNoMobsToolTip);
    if (!(this.field_150939_a instanceof ITileEntityProvider))
        aList.add(this.mNoTileEntityToolTip);

    aList.add(StatCollector.translateToLocal("tooltip.bw.0.name") + ChatColorHelper.DARKGREEN + " BartWorks");
}
 
Example #3
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "itemClass",
        permission = "mytown.adm.cmd.debug.item",
        parentName = "mytown.adm.cmd.debug",
        syntax = "/townadmin debug itemClass",
        console = false)
public static CommandResponse debugItemCommand(ICommandSender sender, List<String> args) {
    if(sender instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer)sender;
        List<Class> list = new ArrayList<Class>();
        if(player.inventory.getCurrentItem() != null) {

            if(player.inventory.getCurrentItem().getItem() instanceof ItemBlock) {
                Block block = ((ItemBlock)player.inventory.getCurrentItem().getItem()).field_150939_a;
                list.add(block.getClass());
                if(block instanceof ITileEntityProvider) {
                	TileEntity te = ((ITileEntityProvider) block).createNewTileEntity(MinecraftServer.getServer().worldServerForDimension(0), 0);
                    list.add(te == null ? TileEntity.class : te.getClass());
                }
            } else {
                list.add(player.inventory.getCurrentItem().getItem().getClass());
            }

            ChatManager.send(sender, new ChatComponentText("For item: " + player.inventory.getCurrentItem().getDisplayName()));
            for(Class cls : list) {
                while (cls != Object.class) {
                    ChatManager.send(sender, new ChatComponentText(cls.getName()));
                    cls = cls.getSuperclass();
                }
            }
        }
    }
    return CommandResponse.DONE;
}
 
Example #4
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void onAnyBlockPlacement(EntityPlayer player, BlockEvent.PlaceEvent ev) {
    if(ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    if(player instanceof FakePlayer) {
        if(!ProtectionManager.getFlagValueAtLocation(FlagType.FAKERS, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
            ev.setCanceled(true);
        }
    } else {
        Resident res = MyTownUniverse.instance.getOrMakeResident(player);

        if (!MyTownUniverse.instance.blocks.contains(ev.world.provider.dimensionId, ev.x >> 4, ev.z >> 4)) {
            int range = Config.instance.placeProtectionRange.get();
            Volume placeBox = new Volume(ev.x-range, ev.y-range, ev.z-range, ev.x+range, ev.y+range, ev.z+range);

            if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, placeBox)) {
                ev.setCanceled(true);
                return;
            }
        } else {
            if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
                ev.setCanceled(true);
                return;
            }
        }

        if(ev.block instanceof ITileEntityProvider && ev.itemInHand != null) {
            TileEntity te = ((ITileEntityProvider) ev.block).createNewTileEntity(MinecraftServer.getServer().worldServerForDimension(ev.world.provider.dimensionId), ev.itemInHand.getItemDamage());
            if (te != null && ProtectionManager.isOwnable(te.getClass())) {
                ThreadPlacementCheck thread = new ThreadPlacementCheck(res, ev.x, ev.y, ev.z, ev.world.provider.dimensionId);
                activePlacementThreads++;
                thread.start();
            }
        }
    }
}
 
Example #5
Source File: BW_MetaGenerated_Blocks.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public TileEntity createTileEntity(World world, int metadata) {
    return ((ITileEntityProvider)this).createNewTileEntity(world, metadata);
}
 
Example #6
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@SuppressWarnings("unchecked")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerBreaksBlock(BlockEvent.BreakEvent ev) {
    if(ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    if(ev.getPlayer() instanceof FakePlayer) {
        if(!ProtectionManager.getFlagValueAtLocation(FlagType.FAKERS, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
            ev.setCanceled(true);
        }
    } else {
        Resident res = MyTownUniverse.instance.getOrMakeResident(ev.getPlayer());

        if (!MyTownUniverse.instance.blocks.contains(ev.world.provider.dimensionId, ev.x >> 4, ev.z >> 4)) {
            int range = Config.instance.placeProtectionRange.get();
            Volume breakBox = new Volume(ev.x-range, ev.y-range, ev.z-range, ev.x+range, ev.y+range, ev.z+range);

            if(!ProtectionManager.checkBlockBreak(ev.block)) {
                if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, breakBox)) {
                    ev.setCanceled(true);
                    return;
                }
            }

        } else {
            if (!ProtectionManager.checkBlockBreak(ev.block)) {
                if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
                    ev.setCanceled(true);
                    return;
                }
            }
        }

        if(ev.getPlayer().getHeldItem() != null) {
            ProtectionManager.checkBreakWithItem(ev.getPlayer().getHeldItem(), res, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev);
        }
    }

    if (!ev.isCanceled() && ev.block instanceof ITileEntityProvider) {
        TileEntity te = ((ITileEntityProvider) ev.block).createNewTileEntity(ev.world, ev.blockMetadata);
        if(te != null && ProtectionManager.isOwnable(te.getClass())) {
            te = ev.world.getTileEntity(ev.x, ev.y, ev.z);
            ownedTileEntities.remove(te);
            MyTown.instance.LOG.info("Removed te {}", te.toString());
        }
    }
}