Search in sources :

Example 1 with AbstractTileHyperSender

use of com.cjm721.overloaded.tile.hyperTransfer.base.AbstractTileHyperSender in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperSender method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (hand == EnumHand.MAIN_HAND) {
        ItemStack heldItem = playerIn.getHeldItem(hand);
        if (heldItem.isEmpty()) {
            // Should find a cleaner way of showing all of this
            if (!worldIn.isRemote) {
                String message = ((AbstractTileHyperSender) worldIn.getTileEntity(pos)).getRightClickMessage();
                playerIn.sendStatusMessage(new TextComponentString(message), false);
            }
        } else if (heldItem.getItem().equals(ModItems.linkingCard)) {
            NBTTagCompound tag = heldItem.getTagCompound();
            if (tag != null) {
                if (tag.getString("TYPE").equals(this.getType())) {
                    int worldID = tag.getInteger("WORLD");
                    int x = tag.getInteger("X");
                    int y = tag.getInteger("Y");
                    int z = tag.getInteger("Z");
                    bindToPartner(worldIn, pos, worldID, new BlockPos(x, y, z));
                    heldItem.setTagCompound(null);
                    if (worldIn.isRemote) {
                        playerIn.sendStatusMessage(new TextComponentString("Bound Hyper Nodes"), true);
                    }
                } else {
                    if (worldIn.isRemote) {
                        playerIn.sendStatusMessage(new TextComponentString("Incorrect Hyper Node Type to bind."), true);
                    }
                }
            }
        }
        return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
Also used : AbstractTileHyperSender(com.cjm721.overloaded.block.tile.hyperTransfer.base.AbstractTileHyperSender) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with AbstractTileHyperSender

use of com.cjm721.overloaded.tile.hyperTransfer.base.AbstractTileHyperSender in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperSender method use.

@Override
@Nonnull
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTraceResult) {
    if (hand == Hand.MAIN_HAND) {
        ItemStack heldItem = player.getItemInHand(hand);
        if (heldItem.isEmpty()) {
            // Should find a cleaner way of showing all of this
            if (!world.isClientSide) {
                String message = ((AbstractTileHyperSender) world.getBlockEntity(pos)).getRightClickMessage();
                player.displayClientMessage(new StringTextComponent(message), false);
            }
            return ActionResultType.SUCCESS;
        } else if (heldItem.getItem().equals(ModItems.linkingCard)) {
            CompoundNBT tag = heldItem.getTag();
            if (tag != null) {
                if (tag.getString("TYPE").equals(this.getType())) {
                    String worldID = tag.getString("WORLD");
                    int x = tag.getInt("X");
                    int y = tag.getInt("Y");
                    int z = tag.getInt("Z");
                    bindToPartner(world, pos, worldID, new BlockPos(x, y, z));
                    if (world.isClientSide) {
                        player.displayClientMessage(new StringTextComponent("Bound Hyper Nodes"), true);
                    }
                } else {
                    if (world.isClientSide) {
                        player.displayClientMessage(new StringTextComponent("Incorrect Hyper Node Type to bind."), true);
                    }
                }
            }
            return ActionResultType.SUCCESS;
        }
    }
    return super.use(state, world, pos, player, hand, rayTraceResult);
}
Also used : AbstractTileHyperSender(com.cjm721.overloaded.tile.hyperTransfer.base.AbstractTileHyperSender) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 AbstractTileHyperSender (com.cjm721.overloaded.block.tile.hyperTransfer.base.AbstractTileHyperSender)1 AbstractTileHyperSender (com.cjm721.overloaded.tile.hyperTransfer.base.AbstractTileHyperSender)1 Nonnull (javax.annotation.Nonnull)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1