• 0

    posted a message on Block detecting arrows that hit him

    Hello, I want to create a block like the target block in the Minecraft 1.7.10 version. I am a beginner in Forge Modding, so I am struggling a lot with it.

    The block should detect arrows that hit him and then tell me where they hit him, so I can calculate a number that should present by a redstone signal how close the block to the center is.

    But my problem is that I do not know how the block can tell me where the arrow is.


    I tried to copy some code of the target of the OpenBlocks Mod, but they have created classes like TileEntityTarget, that extends SyncedTileEntity that extends OpenTileEntity that extends TileEntity so I ended up with trying to edit the code and failing a lot...

    Here is my code:


    @Override
    public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {

    if (!world.isRemote && entity != null && entity instanceof EntityArrow) {
    if (lastEntityHit != entity.getEntityId()) {
    lastEntityHit = entity.getEntityId();
    return;
    }
    lastEntityHit = entity.getEntityId();
    onTargetHit(world, x, y, z, Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ));
    }
    }

    public void onTargetHit(World world, int x, int y, int z, Vec3 entityPosition) {

    if (world.isRemote) return;

    final TileEntity target = getTileEntity(world, x, y, z, TileEntity.class);
    if (target == null) return;

    Vec3 bullseye = Vec3.createVectorHelper(x, y, z);

    double distance = entityPosition.distanceTo(bullseye);

    BlockTargetBlock.setStrength(15 - Math.min(15, Math.max(0, (int)(distance * 32))));

    }

    @Override
    public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int m) {
    final TileEntity tile = getTileEntity(world, x, y, z, TileEntity.class);
    return tile != null? BlockTargetBlock.getStrength() : 0;
    }

    @Override
    public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int m) {
    return isProvidingWeakPower(world, x, y, z, m);
    }

    @Override
    public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
    setBlockBoundsBasedOnState(world, x, y, z);
    return super.getSelectedBoundingBoxFromPool(world, x, y, z);
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
    setBlockBoundsBasedOnState(world, x, y, z);
    return super.getCollisionBoundingBoxFromPool(world, x, y, z);
    }

    private TileEntity getTileEntity(IBlockAccess world, int x, int y, int z, Class<TileEntity> class1) {
    return (worldObj != null && worldObj.blockExists(x, y, z))? worldObj.getTileEntity(x, y, z) : null;
    }

    public static void setStrength(int strength) {
    BlockTargetBlock.strength = strength;
    tickCounter = 10;
    worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, null);
    }

    public static int getStrength() {
    return strength;
    }


    I would be glad if someone could help me out. They don't have to give me the code, it would be enough if I could get a tip or a link to an article or video or something like this that could explain me how I can do it or at least give me also useful tips.


    Greetings,

    Xydru

    Posted in: Modification Development
  • 0

    posted a message on Minecraft Modular Powersuits Power Fist Pickaxe, Axe and Shovel modules not working

    Hey,


    I am playing my modpack in 1.7.10 and I recently crafted a power fist. I installed the pickaxe, axe and shovel modules as well as a battery that is completely charged. I overclocked the modules to harvest speed x30, but there wasn't any effect. It was as fast as a normal stone tool. All the other modules seemed to work fine.

    I didn't set any keybinds, so that can't be the problem and I am in gamemode 0.

    I play on a server, but I also tested it in singleplayer and it didn't work.

    I installed the newest version.


    I would very appreciate it if somebody could help me.


    PS: I tried out different kinds of stone and wood, like cobblestone, clean stone and oak wood, but there was no difference.

    Posted in: Mods Discussion
  • To post a comment, please .